修改kubelet的配置文件/usr/lib/systemd/system/kubelet.service , 使用--pod-manifest-path=/etc/kubernetes/kubelet.d指定静态pod目录 。
[root@k8scloude2 ~]# vim /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf #--pod-manifest-path=/etc/kubernetes/kubelet.d表示静态pod的目录为/etc/kubernetes/kubelet.d[root@k8scloude2 ~]# 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 --pod-manifest-path=/etc/kubernetes/kubelet.d"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
创建静态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钩子 pod:pod hook和优雅的关闭nginx pod
- 2023年农历十月初七能搬家吗
- 2023年农历十月十七搬家怎么样 这天搬入新房会顺利吗
- 2023年农历九月二十七搬家吉利吗 今天宜搬入新家吗
- 2023年农历十一月十七搬家吉利吗今天宜搬入新家吗
- 2023年农历五月二十七办婚礼好不好 这天宜结婚吗
- 2023年农历十一月十七搬家好吗 2023年12月29日适不适合搬家
- 2023年8月28日农历七月十三办开工仪式怎么样 这天开工会顺利吗
- 2022年农历腊月初七是结婚黄道吉日吗
- 2022年农历腊月二十七适合装修新房吗