赞
踩
我们都知道,pod是kubelet创建的,那么创建的流程是什么呐?
此时我们需要了解k8s中config.yaml配置文件了:
他的存放路径: 【/var/lib/kubelet/config.yaml】
[K8S@k8s-master ~]$ sudo cat /var/lib/kubelet/config.yaml
apiVersion: kubelet.config.k8s.io/v1beta1
....
shutdownGracePeriod: 0s
shutdownGracePeriodCriticalPods: 0s
staticPodPath: /etc/kubernetes/manifests
streamingConnectionIdleTimeout: 0s
syncFrequency: 0s
volumeStatsAggPeriod: 0s
我们发现,这里的名称都是我们的k8s集群中master节点的组件
[K8S@k8s-master ~]$ sudo ls -l /etc/kubernetes/manifests/
总用量 16
-rw-------. 1 root root 2246 2月 20 2023 etcd.yaml
-rw------- 1 root root 3382 5月 5 2023 kube-apiserver.yaml
-rw-------. 1 root root 2877 2月 20 2023 kube-controller-manager.yaml
-rw-------. 1 root root 1464 2月 20 2023 kube-scheduler.yaml
查看我们发现这些都是pod资源文件
[K8S@k8s-master ~]$ sudo cat /etc/kubernetes/manifests/etcd.yaml
apiVersion: v1
kind: Pod
metadata:
.....[K8S@k8s-master ~]$ sudo cat /etc/kubernetes/manifests/kube-apiserver.yaml
apiVersion: v1
kind: Pod
metadata:
.....[K8S@k8s-master ~]$ sudo cat /etc/kubernetes/manifests/kube-controller-manager.yaml
apiVersion: v1
kind: Pod
metadata:
.....[K8S@k8s-master ~]$ sudo cat /etc/kubernetes/manifests/kube-scheduler.yaml
apiVersion: v1
kind: Pod
metadata:
.....
所谓的静态pod,就是kubelet自己监视的目录,如果这个目录有pod资源清单,则会在当前节点自动创建pod,
不需要手动kubectl apply -f xxx.yaml,就是我们只要把pod的资源文件移到 /etc/kubernetes/manifests/ 目录下,就是自动创建
静态pod的创建,只在当前节点上创建,pod的名称会自动给你加一个当前节点名称后缀
[root@master study-demo]# cat firstpod.yml
apiVersion: v1
kind: Pod
metadata:
name: first-pod
labels:
app: demo
spec:
containers:
- name: busybox-container
image: nginx
[root@master study-demo]# kubectl get pod
No resources found in default namespace.
[root@master study-demo]# cp firstpod.yml /etc/kubernetes/manifests/ #拷贝到pod静态资源文件中[root@master study-demo]# ls -l /etc/kubernetes/manifests/
总用量 20
-rw------- 1 root root 2256 3月 29 16:03 etcd.yaml
-rw-r--r-- 1 root root 143 4月 18 16:39 firstpod.yml
-rw------- 1 root root 3381 3月 29 16:03 kube-apiserver.yaml
-rw------- 1 root root 2877 3月 29 16:03 kube-controller-manager.yaml
-rw------- 1 root root 1464 3月 29 16:03 kube-scheduler.yaml
[root@master study-demo]# kubectl get pod #我们发现重启了
NAME READY STATUS RESTARTS AGE
first-pod-master 1/1 Running 0 22s
[root@master study-demo]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
first-pod-master 1/1 Running 0 28s 10.244.0.24 master <none> <none>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。