K8S基础:Pod管理

网友投稿 231 2022-10-21

K8S基础:Pod管理

1、命名空间管理

#创建 [root@master ~]# kubectl create ns leoheng namespace/leoheng created #删除 [root@master ~]# kubectl delete ns leoheng namespace "leoheng" deleted

2、管理指定命名空间资源

#创建 [root@master server]# vim leoheng.yaml apiVersion: v1 kind: Namespace metadata: name: leoheng [root@master server]# kubectl apply -f leoheng.yaml namespace/leoheng created [root@master server]# kubectl get ns NAME STATUS AGE default Active 10h kube-node-lease Active 10h kube-public Active 10h kube-system Active 10h kubekey-system Active 10h kubernetes-dashboard Active 31m kubesphere-controls-system Active 10h kubesphere-monitoring-federated Active 10h kubesphere-monitoring-system Active 10h kubesphere-system Active 10h leoheng Active 106s [root@master server]# #删除 [root@master server]# kubectl delete -f leoheng.yaml namespace "leoheng" deleted [root@master server]#

3、kubectl管理命令行创建的Pod

#kubectl创建pod [root@master server]# kubectl run mynginx --image=nginx pod/mynginx created [root@master server]# kubectl get pod mynginx NAME READY STATUS RESTARTS AGE mynginx 1/1 Running 0 82s #查看POD创建信息 [root@master server]# kubectl describe pod mynginx Name: mynginx Namespace: default Priority: 0 Node: node01/172.18.0.3 Start Time: Wed, 13 Apr 2022 10:38:48 +0800 Labels: run=mynginx Annotations: cni.projectcalico.org/containerID: 7bfaaddc892626b58ccb6a8c9b376d25fc52387476f4475a17ed87d04cbd6258 cni.projectcalico.org/podIP: 10.233.82.18/32 cni.projectcalico.org/podIPs: 10.233.82.18/32 Status: Running IP: 10.233.82.18 IPs: IP: 10.233.82.18 Containers: mynginx: Container ID: docker://c3742edb8fd542d7131e73a626df41f1c43efda510c4de985ff6c3f0fc5ef86f Image: nginx Image ID: docker-pullable://nginx@sha256:2275af0f20d71b293916f1958f8497f987b8d8fd8113df54635f2a5915002bf1 Port: Host Port: State: Running Started: Wed, 13 Apr 2022 10:39:46 +0800 Ready: True Restart Count: 0 Environment: Mounts: /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-z957h (ro) Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled True Volumes: kube-api-access-z957h: Type: Projected (a volume that contains injected data from multiple sources) TokenExpirationSeconds: 3607 ConfigMapName: kube-root-ca.crt ConfigMapOptional: DownwardAPI: true QoS Class: BestEffort Node-Selectors: Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s node.kubernetes.io/unreachable:NoExecute op=Exists for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 108s default-scheduler Successfully assigned default/mynginx to node01 Normal Pulling 107s kubelet Pulling image "nginx" Normal Pulled 53s kubelet Successfully pulled image "nginx" in 54.078383333s Normal Created 50s kubelet Created container mynginx Normal Started 50s kubelet Started container mynginx [root@master server]# #删除pod [root@master server]# kubectl delete pod mynginx pod "mynginx" deleted

4、管理yaml文件创建的pod

#编辑yaml文件,创建pod [root@master server]# vim pod.yaml apiVersion: v1 kind: Pod metadata: labels: run: myinginx name: myinginx spec: containers: - image: nginx name: nginx01 [root@master server]# kubectl apply -f pod.yaml pod/myinginx created [root@master server]# kubectl get pod myinginx NAME READY STATUS RESTARTS AGE myinginx 1/1 Running 0 17m #查看pod创建过程 [root@master server]# kubectl describe pod myinginx Name: myinginx Namespace: default Priority: 0 Node: node01/172.18.0.3 Start Time: Wed, 13 Apr 2022 10:55:46 +0800 Labels: run=myinginx Annotations: cni.projectcalico.org/containerID: b988c64354fb9749c7a1bb5c209cd18d8c32d0994bea3c263707e82dcf9b5205 cni.projectcalico.org/podIP: 10.233.82.19/32 cni.projectcalico.org/podIPs: 10.233.82.19/32 Status: Running IP: 10.233.82.19 IPs: IP: 10.233.82.19 Containers: nginx01: Container ID: docker://af7d0f9fa682b1913f047186ac694b72b5313b973c3564fa634cb4765f0da913 Image: nginx Image ID: docker-pullable://nginx@sha256:2275af0f20d71b293916f1958f8497f987b8d8fd8113df54635f2a5915002bf1 Port: Host Port: State: Running Started: Wed, 13 Apr 2022 10:55:50 +0800 Ready: True Restart Count: 0 Environment: Mounts: /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-h2d86 (ro) Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled True Volumes: kube-api-access-h2d86: Type: Projected (a volume that contains injected data from multiple sources) TokenExpirationSeconds: 3607 ConfigMapName: kube-root-ca.crt ConfigMapOptional: DownwardAPI: true QoS Class: BestEffort Node-Selectors: Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s node.kubernetes.io/unreachable:NoExecute op=Exists for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 16m default-scheduler Successfully assigned default/myinginx to node01 Normal Pulling 16m kubelet Pulling image "nginx" Normal Pulled 16m kubelet Successfully pulled image "nginx" in 3.01552082s Normal Created 16m kubelet Created container nginx01 Normal Started 16m kubelet Started container nginx01 #通过yaml文件删除相关pod [root@master server]# kubectl delete -f pod.yaml pod "myinginx" deleted [root@master server]#

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:使用Prometheus监控自建Mysql
下一篇:harbor密码丢失,忘记Harbor密码?
相关文章

 发表评论

暂时没有评论,来抢沙发吧~