时间:2023-01-30 10:34:37 | 栏目:Nginx | 点击:次
DaemonSet是守护进程集,简写为ds;是在所有的节点或者匹配的节点上都部署一个Pod。
[root@k8s-master01 ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-master01 Ready <none> 8d v1.23.3 k8s-master02 Ready <none> 8d v1.23.3 k8s-master03 Ready <none> 8d v1.23.3 k8s-node01 Ready <none> 8d v1.23.3 k8s-node02 Ready <none> 8d v1.23.3
比如从上段代码中可以看到我们集群有五个节点,Daemon会在这五个节点都部署一个Pod;又或者我们只需要在node节点部署,那么可以利用标签的方式只在node节点上部署Pod。比如我们的calico网络插件就是用DaemonSet部署的。
apiVersion: apps/v1 kind: DaemonSet metadata: labels: app: nginx name: nginx spec: revisionHistoryLimit: 10 selector: matchLabels: app: nginx template: metadata: creationTimestamp: null labels: app: nginx spec: containers: - name: nginx image: nginx:1.18.0 imagePullPolicy: Always resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30
注意:没有副本数的参数
创建一个ds;然后查看可以看到每个节点上都生成了一个nginx副本。
[root@k8s-master01 ~]# kubectl create -f nginx-ds.yaml daemonset.apps/nginx created [root@k8s-master01 ~]# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES busybox 1/1 Running 21 (2m45s ago) 8d 172.27.14.193 k8s-node02 <none> <none> nginx-2c7xf 1/1 Running 0 2m2s 172.25.92.79 k8s-master02 <none> <none> nginx-kjdx8 1/1 Running 0 2m2s 172.25.244.200 k8s-master01 <none> <none> nginx-wwltz 1/1 Running 0 2m2s 172.27.14.199 k8s-node02 <none> <none> nginx-zl2lr 1/1 Running 0 2m2s 172.18.195.19 k8s-master03 <none> <none> nginx-znprg 1/1 Running 0 2m2s 172.17.125.7 k8s-node01 <none> <none>
需要注意的地方:
其他地方与Deployment和StatefulSet类似,就不说了,可以看我另外两篇!