@Pod中的容器类型
(1)Infrastructure Container 基础容器
共用pause的网络栈和存储卷,只要有pod,容器pause就会启动
在任意节点查看容器,可以看到一个Pod(可能包含一个或多个容器)对应一个pause
[root@k8s-node1 manifests]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
37c42e23779d nginx "/docker-entrypoint.…" 10 hours ago Up 10 hours k8s_nginx_test-probe-766bcd6cf-tx52m_default_5e84e70e-402d-4c5d-91ad-5ca209fb230b_0
cf2e8f0fd3a4 nginx "/docker-entrypoint.…" 10 hours ago Up 10 hours k8s_nginx_test-probe-766bcd6cf-p9f8p_default_0ae8718a-062b-4461-86c5-9f2e534bc8b7_0
630c2e8df100 registry.aliyuncs.com/google_containers/pause:3.2 "/pause" 10 hours ago Up 10 hours k8s_POD_test-probe-766bcd6cf-p9f8p_default_0ae8718a-062b-4461-86c5-9f2e534bc8b7_0
bd0aa978a8d8 registry.aliyuncs.com/google_containers/pause:3.2 "/pause" 10 hours ago Up 10 hours k8s_POD_test-probe-766bcd6cf-tx52m_default_5e84e70e-402d-4c5d-91ad-5ca209fb230b_0
e5ca0e01ba6c nginx "/docker-entrypoint.…" 11 hours ago Up 11 hours k8s_nginx_pod-01-f6cdbd6c9-p9t7g_aliang-cka_74f4b7c9-0c26-425b-8eb2-8e506b9b40cf_9
97b58cab095a 1470783b1474 "start_runit" 11 hours ago Up 11 hours k8s_calico-node_calico-node-q6qxm_kube-system_fde756c0-dea4-4e43-b0fd-bf76ff758bf4_15
ea7c0a45c66e registry.aliyuncs.com/google_containers/pause:3.2 "/pause" 11 hours ago Up 11 hours k8s_POD_pod-01-f6cdbd6c9-p9t7g_aliang-cka_74f4b7c9-0c26-425b-8eb2-8e506b9b40cf_9
e9a7ba202fab 10cc881966cf "/usr/local/bin/kube…" 11 hours ago Up 11 hours k8s_kube-proxy_kube-proxy-clmzc_kube-system_89972005-0074-4aad-a9f6-d9928e80e0b8_15
905d12edd8ce registry.aliyuncs.com/google_containers/pause:3.2 "/pause" 11 hours ago Up 11 hours k8s_POD_calico-node-q6qxm_kube-system_fde756c0-dea4-4e43-b0fd-bf76ff758bf4_15
3f59d74236b4 registry.aliyuncs.com/google_containers/pause:3.2 "/pause" 11 hours ago Up 11 hours k8s_POD_kube-proxy-clmzc_kube-system_89972005-0074-4aad-a9f6-d9928e80e0b8_15
[root@k8s-node1 manifests]#
(2)InitContainer 初始化容器
先于应用容器执行,用于初始化工作,执行完就结束
可用于如下场景
环境检查 -> 确保应用容器依赖的服务启动后再启动应用容器
初始化配置 -> 为应用容器准备配置文件
(3)Containers 业务容器
@静态Pod
静态Pod路径参数
[root@k8s-master ~]# grep static /var/lib/kubelet/config.yaml
staticPodPath: /etc/kubernetes/manifests
[root@k8s-master ~]#
将pod yaml放到路径/etc/kubernetes/manifests会由kubelet自动创建
[root@k8s-master manifests]# pwd
/etc/kubernetes/manifests
[root@k8s-master manifests]# ls -l
total 16
-rw------- 1 root root 2232 Jul 26 00:01 etcd.yaml
-rw------- 1 root root 3340 Jul 26 00:01 kube-apiserver.yaml
-rw------- 1 root root 2828 Aug 7 09:59 kube-controller-manager.yaml
-rw------- 1 root root 1414 Aug 7 09:59 kube-scheduler.yaml
[root@k8s-master manifests]#
【例】/root/teststaticpod.yaml内容如下
apiVersion: v1
kind: Pod
metadata:
name: testpod
spec:
containers:
- image: nginx
name: testpod
将其放置到节点k8s-master的路径/etc/kubernetes/manifests,可以看到新拉起了一个Pod,其名称的后半部分是节点名称
[root@k8s-master manifests]# kubectl get pod -o wide
No resources found in default namespace.
[root@k8s-master manifests]#
[root@k8s-master manifests]# mv /root/teststaticpod.yaml ./
[root@k8s-master manifests]#
[root@k8s-master manifests]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
testpod-k8s-master 1/1 Running 0 5s 10.244.235.226 k8s-master <none> <none>
[root@k8s-master manifests]#
再将该Pod的yaml文件挪走,可以看到刚才拉起的Pod没了
[root@k8s-master manifests]# mv teststaticpod.yaml /root
[root@k8s-master manifests]#
[root@k8s-master manifests]# kubectl get pod -o wide
No resources found in default namespace.
[root@k8s-master manifests]#