有一种比《研发工程师玩转Kubernetes——利用Pod反亲和性控制一个Node上只能有一个Pod》一文中介绍的更简单的方法控制一个Node上只有一个Pod,那就是使用DaemonSet。
代码语言:javascript复制apiVersion: apps/v1
kind: DaemonSet
metadata:
name: nginx-daemonset
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
通过上述清单文件创建Pod。可以看到每个Node都被部署了一个Pod。
代码语言:javascript复制kubectl get pod -o wide
代码语言:javascript复制NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-daemonset-kl9jm 1/1 Running 0 4m23s 10.1.202.212 ubuntud <none> <none>
nginx-daemonset-zr8k7 1/1 Running 0 4m23s 10.1.94.67 ubuntua <none> <none>
nginx-daemonset-z2ptj 1/1 Running 0 4m23s 10.1.209.145 ubuntub <none> <none>
nginx-daemonset-6c2vp 1/1 Running 0 4m23s 10.1.226.1 ubuntue <none> <none>
nginx-daemonset-tbj4w 1/1 Running 0 4m23s 10.1.43.209 ubuntuc <none> <none>