[root@k8s-master01 ~]# kubectl get po -n kube-system
NAME READY STATUS RESTARTS AGE
metrics-server-64c6c494dc-lhkl2 1/1 Running 1 (82m ago) 87m
Pause容器
[root@k8s-master01 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b30c03e6e0ff 9759a41ccdf0 "/metrics-server --c…" About an hour ago Up About an hour k8s_metrics-server_metrics-server-64c6c494dc-lhkl2_kube-system_517b9ab1-a323-4530-8be4-ebd3a7d41de4_1
f45e50c4009e registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.2 "/pause" About an hour ago Up About an hour k8s_POD_metrics-server-64c6c494dc-lhkl2_kube-system_517b9ab1-a323-4530-8be4-ebd3a7d41de4_1
[root@k8s-master01 ~]# kubectl create -f pod.yaml
pod/nginx created
获取IP
[root@k8s-master01 ~]# kubectl get po -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx 1/1 Running 0 2m31s 172.25.244.217 k8s-master01 <none> <none>
访问nginx
[root@k8s-master01 ~]# curl 172.25.244.217
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@k8s-master01 ~]# kubectl delete po nginx
pod "nginx" deleted
[root@k8s-master01 ~]# kubectl create -f pod.yaml
pod/nginx created
查看pod
[root@k8s-master01 ~]# kubectl get po
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 4s
[root@k8s-master01 ~]# kubectl describe po nginx
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 10s default-scheduler Successfully assigned default/nginx to k8s-master01
Warning Unhealthy 2s (x2 over 6s) kubelet Liveness probe failed: OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "pgrep nginx": executable file not found in $PATH: unknown
Normal Pulled 1s (x3 over 9s) kubelet Container image "nginx:latest" already present on machine
Normal Created 1s (x3 over 9s) kubelet Created container nginx
Normal Started 1s (x3 over 9s) kubelet Started container nginx
Normal Killing 1s (x2 over 5s) kubelet Container nginx failed liveness probe, will be restarted
可以看到如果exec的命令不存在会报错Liveness probe failed
修改exec命令为ls
exec: # 执行容器命令检测方式
command:
- ls
重新创建
[root@k8s-master01 ~]# kubectl delete po nginx
pod "nginx" deleted
[root@k8s-master01 ~]# kubectl create -f pod.yaml
pod/nginx created
[root@k8s-master01 ~]# kubectl get po
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 4s
[root@k8s-master01 ~]# kubectl describe po nginx
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 8s default-scheduler Successfully assigned default/nginx to k8s-master01
Normal Pulled 7s kubelet Container image "nginx:latest" already present on machine
Normal Created 7s kubelet Created container nginx
Normal Started 7s kubelet Started container nginx
[root@k8s-master01 ~]# kubectl delete po nginx
pod "nginx" deleted
[root@k8s-master01 ~]# kubectl create -f pod.yaml
pod/nginx created
[root@k8s-master01 ~]# kubectl get po
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 28s
查看pod退出时间
[root@k8s-master01 ~]# time kubectl delete po nginx
pod "nginx" deleted
real 0m40.249s
user 0m0.038s
sys 0m0.019s
[root@k8s-master01 ~]# kubectl create -f pod.yaml
pod/nginx created
[root@k8s-master01 ~]# kubectl get po
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 28s
查看pod退出时间
[root@k8s-master01 ~]# time kubectl delete po nginx
pod "nginx" deleted
real 0m51.427s
user 0m0.031s
sys 0m0.017s