一、DaemonSet作用
Relicationcontroller和ReplicaSet都用于在Kubernetes集群上运行部署特定数量的pod。但是,当你希望pod在集群中的每个节点上运行时,就可使用DaemonSet。
apiVersion: apps/v1beta2
kind: DaemonSet
metadata:
name: ssd-monitor
namespace: test
spec:
selector:
matchLabels:
app: ssd-monitor
template:
metadata:
labels:
app: ssd-monitor
spec:
nodeSelector: #指定节点标签disk带有ssd的主机上运行
disk: ssd #如没有nodeSelector,即会在所有节点上运行一个POD
containers:
- name: main
image: luksa/ssd-monitor
[[email protected] k8s-yaml-file]# kubectl get nodes -l disk=ssd
#查看带有disk=ssd的标签
NAME STATUS ROLES AGE VERSION
test-nodes1.cedarhd.com Ready master,node 66d v1.15.2
test-nodes2.cedarhd.com Ready master,node 66d v1.15.2
[[email protected] k8s-yaml-file]# kubectl label node test-nodes1.cedarhd.com disk=hhd --overwrite
#修改其中一个节点的标签不带disk=ssd
node/test-nodes1.cedarhd.com labeled
[[email protected] k8s-yaml-file]# kubectl get nodes -l disk=ssd
NAME STATUS ROLES AGE VERSION
test-nodes2.cedarhd.com Ready master,node 66d v1.15.2
[[email protected] k8s-yaml-file]# kubectl create -f kubia-daemonset.yaml
#创建DaemonSet
daemonset.apps/ssd-monitor created
[[email protected] k8s-yaml-file]# kubectl get pod -o wide -n test
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
ssd-monitor-q7kbz 1/1 Running 0 16s 172.7.22.6 test-nodes2.cedarhd.com <none> <none>
[[email protected] k8s-yaml-file]# kubectl get ds -n test
#查看DaemonSet
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
ssd-monitor 1 1 1 1 1 disk=ssd 5m7s
原文地址:https://blog.51cto.com/12965094/2485526
时间: 2024-10-25 15:40:24