创建静态pod目录,并使kubelet配置文件生效
[root@k8scloude2 ~]# mkdir /etc/kubernetes/kubelet.d[root@k8scloude2 ~]# systemctl daemon-reload [root@k8scloude2 ~]# systemctl restart kubelet[root@k8scloude2 ~]# systemctl status kubelet● kubelet.service - kubelet: The Kubernetes Node AgentLoaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)Drop-In: /usr/lib/systemd/system/kubelet.service.d└─10-kubeadm.confActive: active (running) since 六 2022-01-15 18:02:15 CST; 6s agoDocs: https://kubernetes.io/docs/ Main PID: 108844 (kubelet)Memory: 30.7MCGroup: /system.slice/kubelet.service├─108844 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --pod-manifest-path=/etc/kubernetes/kubelet.d --config=/var/lib/ku...└─108999 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --pod-manifest-path=/etc/kubernetes/kubelet.d --config=/var/lib/ku...
进入静态pod的目录,然后创建pod yaml文件
[root@k8scloude2 ~]# cd /etc/kubernetes/kubelet.d/[root@k8scloude2 kubelet.d]# ls[root@k8scloude2 kubelet.d]# vim pod.yaml[root@k8scloude2 kubelet.d]# cat pod.yamlapiVersion: v1kind: Podmetadata:creationTimestamp: nulllabels:run: podname: podspec:containers:- image: nginximagePullPolicy: IfNotPresentname: podresources: {}ports:- name: httpcontainerPort: 80protocol: TCPdnsPolicy: ClusterFirstrestartPolicy: Alwaysstatus: {}
在k8s集群的master节点上查看pod,在master上可以看到该pod,由于pod.yaml没有指定namespace,默认在default下,可以看到Pod 名称(pod-k8scloude2)是以连字符开头的节点主机名作为后缀 。
[root@k8scloude1 pod]# kubectl get pods -n default -o wideNAMEREADYSTATUSRESTARTSAGEIPNODENOMINATED NODEREADINESS GATESpod-k8scloude21/1Running0109s10.244.112.153k8scloude2<none><none>
当把这个pod.yaml文件从静态pod目录移走,pod就消失了
[root@k8scloude2 kubelet.d]# mv pod.yaml ~/[root@k8scloude2 kubelet.d]# ls#当把这个yaml文件移走,pod消失[root@k8scloude1 pod]# kubectl get pods -n default -o wideNo resources found in default namespace.
现在指定静态pod的namespace为pod
[root@k8scloude2 kubelet.d]# vim pod.yaml #namespace: pod:指定pod的命名空间[root@k8scloude2 kubelet.d]# cat pod.yamlapiVersion: v1kind: Podmetadata:creationTimestamp: nulllabels:run: podname: podnamespace: podspec:containers:- image: nginximagePullPolicy: IfNotPresentname: podresources: {}ports:- name: httpcontainerPort: 80protocol: TCPdnsPolicy: ClusterFirstrestartPolicy: Alwaysstatus: {}[root@k8scloude2 kubelet.d]# lspod.yaml
查看pod
[root@k8scloude1 pod]# kubectl get pods -n podNAMEREADYSTATUSRESTARTSAGEpod-k8scloude21/1Running06s
3.2.2 静态pod默认目录/etc/kubernetes/manifests注意:进行这一步的时候,先还原kubelet配置文件/usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf
查看配置文件,可以发现静态pod默认目录为/etc/kubernetes/manifests
[root@k8scloude2 kubelet.d]# cat /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf# Note: This dropin only works with kubeadm and kubelet v1.11+[Service]Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamicallyEnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.EnvironmentFile=-/etc/sysconfig/kubeletExecStart=ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS[root@k8scloude2 kubelet.d]# ls /var/lib/kubelet/config.yaml/var/lib/kubelet/config.yaml[root@k8scloude2 kubelet.d]# cat /var/lib/kubelet/config.yaml | grep manifeststaticPodPath: /etc/kubernetes/manifests#默认的静态pod的目录为 ls /etc/kubernetes/manifests[root@k8scloude2 kubelet.d]# ls /etc/kubernetes/manifests
在默认的静态pod目录/etc/kubernetes/manifests/下创建pod yaml文件
#namespace: pod:指定pod的命名空间[root@k8scloude2 kubelet.d]# vim ~/pod.yaml [root@k8scloude2 kubelet.d]# cat ~/pod.yamlapiVersion: v1kind: Podmetadata:creationTimestamp: nulllabels:run: podname: podnamespace: podspec:containers:- image: nginximagePullPolicy: IfNotPresentname: podresources: {}ports:- name: httpcontainerPort: 80protocol: TCPdnsPolicy: ClusterFirstrestartPolicy: Alwaysstatus: {}[root@k8scloude2 kubelet.d]# cp ~/pod.yaml /etc/kubernetes/manifests/
推荐阅读
- 五 pod钩子 pod:pod hook和优雅的关闭nginx pod
- 我的世界地狱门怎么做(mc七种传送门)
- 有哪些在家用电脑就可以赚钱的办法,一天七八十就可以了
- 原神静态风景后篇9号宝箱怎么开启
- 梦幻西游手游妙法试炼第七章怎么通关
- LolliPods plus和pro有什么差别_LolliPods plus和pro怎么选择
- 伍六七第三季更新时间_伍六七第三季什么时候更新
- 鸡皮疙瘩第七关同学会怎么过
- GCC 指令详解及动态库、静态库的使用
- airpods pro续航时间多久_airpods pro续航实测