yaml文件示例

apiVersion: v1 kind: Pod metadata: name: pod-2 # labels: # run: mytest-pod-2 spec: containers: - imagePullPolicy: IfNotPresent image: httpd name: httpd ports: - containerPort: 80 - imagePullPolicy: IfNotPresent image: panubo/sshd name: sshd ports: - containerPort: 22
kubectl create namepsace ns006
kubectl create -f pod-2.yaml -n ns006
kubectl exec pod-2 -c sshd -n ns006 -- ls
kubectl exec pod-2 -c httpd-n ns006 -- ls

apiVersion: v1 kind: Service metadata: name: my-svc #定义服务的名称 spec: ports: - name: tomcat port: 8080 #POD暴露的cluster-ip端口 targetPort: 8080 #container暴露的端口,容器expose暴露的端口 protocol: TCP nodePort: 30001 #物理节点对外暴露的端口,提供给外部访问service的入口 selector: app: npu type: NodePort