多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
**1. 一个容器组成的Pod的 `pod01.yaml` 示例** ```yml apiVersion: v1 kind: Pod metadata: name: mytomcat labels: name: mytomcat spec: containers: - name: mytomcat image: tomcat ports: - containerPort: 8000 ``` **2. 多个容器组成的Pod的 `pod02.yaml` 示例** ```yml apiVersion: v1 kind: Pod metadata: name: myweb labels: name: tomcat-redis spec: containers: - name: tomcat image: tomcat ports: - containerPort: 8000 - name: redis image: redis ports: - containerPort: 6379 ``` **3. 创建Pod** 语法: ```shell kubectl create -f xxx.yaml ``` 示例: ```shell # kubectl create -f pod02.yaml pod/myweb created ``` **4. 查看** 语法: ```shell 语法1:kubectl get pod <Pod_name> 语法2:kubectl get po <Pod_name> 语法3:kubectl get pod <Pod_name> -o wide 语法4:kubectl get po <Pod_name> -o wide 语法5:kubectl describe pod <Pod_name> 语法6:kubectl describe po <Pod_name> ``` 示例: ```shell (1)方式1 # kubectl get pod myweb NAME READY STATUS RESTARTS AGE myweb 0/2 ContainerCreating 0 99s (2)方式2 # kubectl get po myweb NAME READY STATUS RESTARTS AGE myweb 0/2 ContainerCreating 0 113s (3)方式3 # kubectl get pod myweb -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES myweb 0/2 ContainerCreating 0 2m56s <none> k8s-node-02 <none> <none> (4)方式4 # kubectl describe pod myweb Name: myweb Namespace: default Priority: 0 Node: k8s-node-02/192.168.1.13 Start Time: Thu, 17 Feb 2022 21:09:06 +0800 Labels: name=tomcat-redis Annotations: <none> Status: Pending IP: IPs: <none> Containers: tomcat: Container ID: Image: tomcat Image ID: Port: 8000/TCP Host Port: 0/TCP State: Waiting Reason: ContainerCreating Ready: False Restart Count: 0 Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-br2cp (ro) redis: Container ID: Image: redis Image ID: Port: 6379/TCP Host Port: 0/TCP State: Waiting Reason: ContainerCreating Ready: False Restart Count: 0 Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-br2cp (ro) Conditions: Type Status Initialized True Ready False ContainersReady False PodScheduled True Volumes: default-token-br2cp: Type: Secret (a volume populated by a Secret) SecretName: default-token-br2cp Optional: false QoS Class: BestEffort Node-Selectors: <none> Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s node.kubernetes.io/unreachable:NoExecute for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled <unknown> default-scheduler Successfully assigned default/myweb to k8s-node-02 Normal Pulling 3m15s kubelet, k8s-node-02 Pulling image "tomcat" ``` **5. 删除** 语法: ```shell 语法1:kubectl delete -f pod <Pod_name>.yaml 语法2:kubectl delete pod --all 语法3:kubectl delete pod <Pod_name> ``` 示例: ```shell # kubectl delete -f pod myweb.yaml # kubectl delete pod myweb pod "myweb" deleted ```