目录
1、查看某个资源的详细信息:kubectl describe pod pod_name -n nameapace
2、查看指定命名空间中pod的基本信息:kubectl get pods -n namespace
3、跨主机登录容器:kubectl exec -it pod_name /bin/bash -n namespace
4.1、直接删除pod。但是deployment,副本控制器还在,他就会自己再创建一个。
4.3、如果删除过程中出现幺蛾子,Pod无法删除,总是处于terminating状态,则执行强行删除--force --grace-period=0
1、创建一个Pod,启动nginx实例,暴露容器80端口,设置副本集为3(创建pod)
一、kubectl命令详解
1、查看某个资源的详细信息:kubectl describe pod pod_name -n nameapace(不加-n namespace 默认为查看default命名空间资源)
[root@master ~]# kubectl describe pods -n kube-public
### 查看指定命名空间中的pod的详细信息
### 在处理故障时,常使用此命令查看pod 的events信息来定位问题
Name: nginx-w1-7464d66457-psk6h
Namespace: kube-public
Priority: 0
Node: node01/192.168.159.11
Start Time: Wed, 02 Nov 2022 01:40:47 +0800
Labels: app=nginx-w1
pod-template-hash=7464d66457
Annotations: <none>
Status: Running
IP: 10.150.1.3
IPs:
IP: 10.150.1.3
Controlled By: ReplicaSet/nginx-w1-7464d66457
Containers:
nginx:
Container ID: docker://4011df060a9ad777793f061675fc1a784f4effe56f5585d91d5ba3670660c620
Image: nginx
Image ID: docker-pullable://nginx@sha256:943c25b4b66b332184d5ba6bb18234273551593016c0e0ae906bab111548239f
Port: <none>
Host Port: <none>
State: Running
Started: Wed, 02 Nov 2022 01:41:06 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-llzgh (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-llzgh:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events: <none>
Name: nginx-x1-77484d895f-ddhqt
Namespace: kube-public
Priority: 0
Node: node02/192.168.159.13
Start Time: Thu, 03 Nov 2022 16:16:11 +0800
Labels: app=nginx-x1
pod-template-hash=77484d895f
Annotations: <none>
Status: Running
IP: 10.150.2.3
IPs:
IP: 10.150.2.3
Controlled By: ReplicaSet/nginx-x1-77484d895f
Containers:
nginx:
Container ID: docker://ecc07803682f2d7a51037024354dae0d190841443121ca0a8514ab224179cbf5
Image: nginx:latest
Image ID: docker-pullable://nginx@sha256:943c25b4b66b332184d5ba6bb18234273551593016c0e0ae906bab111548239f
Port: <none>
Host Port: <none>
State: Running
Started: Thu, 03 Nov 2022 16:16:36 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-47hxr (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-47hxr:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events: <none>