kubernetes-daemonset
保证pod高可用,监控pod运行状态,保证无时无刻都有期望的pod副本运行,要求同一个daemonset部署出来的pod一定要运行不同节点,保证节点 (有且只有一个pod),一般做agent代理程序或监控,没副本数,等于节点数量。
可以直接拷贝deployment的yaml文件直接更改
[root@master01 ~]# cat deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: my-dep
apiVersion: apps/v1
kind: DaemonSet
metadata:
creationTimestamp: null
labels:
app: my-dae
name: my-dae
spec:
selector:
matchLabels:
app: my-daemon
template:
metadata:
creationTimestamp: null
labels:
app: my-daemon
spec:
containers:
- image: nginx
name: nginx
imagePullPolicy: IfNotPresent
resources: {}
创建daemonset ,默认不会调度到master 上,因为master有污点。后面再写污点和容忍度。
只调度至work工作节点
[root@master01 ~]# kubectl create -f daemonset.yaml
daemonset.apps/my-dae created
[root@master01 ~]# kubectl get daemonsets.apps my-dae
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
my-dae 2 2 2 2 2 <none> 9s
[root@master01 ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
my-dae-g5gww 1/1 Running 0 15s 10.244.196.185 node01 <none> <none>
my-dae-r2kmg 1/1 Running 0 15s 10.244.140.118 node02 <none> <none>
删除一个pod ,daemonset 也会从新拉起一个新的pod
[root@master01 ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
my-dae-g5gww 1/1 Running 0 15s 10.244.196.185 node01 <none> <none>
my-dae-r2kmg 1/1 Running 0 15s 10.244.140.118 node02 <none> <none>
[root@master01 ~]#
[root@master01 ~]# kubectl delete pods my-dae-r2kmg
pod "my-dae-r2kmg" deleted
[root@master01 ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
my-dae-g5gww 1/1 Running 0 3m3s 10.244.196.185 node01 <none> <none>
my-dae-r82dp 1/1 Running 0 2s 10.244.140.119 node02 <none> <none>
创建一个容忍master污点的daemonset
[root@master01 ~]# kubectl create -f daemon.yaml
daemonset.apps/my-dae created
[root@master01 ~]# kubectl get daemonsets.apps my-dae
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
my-dae 3 3 3 3 3 kubernetes.io/os=linux 11s
[root@master01 ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
my-dae-km5jw 1/1 Running 0 16s 10.244.140.120 node02 <none> <none>
my-dae-lkhs7 1/1 Running 0 16s 10.244.196.186 node01 <none> <none>
my-dae-xnp6q 1/1 Running 0 16s 10.244.241.71 master01 <none> <none> #master
[root@master01 ~]# cat daemon.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
creationTimestamp: null
labels:
app: my-dae
name: my-dae
spec:
selector:
matchLabels:
app: my-daemon
template:
metadata:
creationTimestamp: null
labels:
app: my-daemon
spec:
containers:
- image: nginx
name: nginx
imagePullPolicy: IfNotPresent
resources: {}
nodeSelector: #node筛选器
kubernetes.io/os: linux
tolerations: #容忍污点
- key: "node-role.kubernetes.io/master"
operator: "Exists"
value: ""
effect: "NoSchedule"
升级回滚 同deployment一样
[root@master01 ~]# kubectl set image daemonset.apps my-dae nginx=nginx:1.16.1 --record
Flag --record has been deprecated, --record will be removed in the future
daemonset.apps/my-dae image updated
[root@master01 ~]# kubectl describe daemonsets.apps my-dae
Name: my-dae
Selector: app=my-daemon
Node-Selector: kubernetes.io/os=linux
Labels: app=my-dae
Annotations: deprecated.daemonset.template.generation: 2
kubernetes.io/change-cause: kubectl set image daemonset.apps my-dae nginx=nginx:1.16.1 --record=true
Desired Number of Nodes Scheduled: 3
Current Number of Nodes Scheduled: 3
Number of Nodes Scheduled with Up-to-date Pods: 2
Number of Nodes Scheduled with Available Pods: 2
Number of Nodes Misscheduled: 0
Pods Status: 2 Running / 1 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: app=my-daemon
Containers:
nginx:
Image: nginx:1.16.1
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 3m24s daemonset-controller Created pod: my-dae-lkhs7
Normal SuccessfulCreate 3m24s daemonset-controller Created pod: my-dae-km5jw
Normal SuccessfulCreate 3m24s daemonset-controller Created pod: my-dae-xnp6q
Normal SuccessfulDelete 16s daemonset-controller Deleted pod: my-dae-lkhs7
Normal SuccessfulCreate 15s daemonset-controller Created pod: my-dae-g5rwb
Normal SuccessfulDelete 13s daemonset-controller Deleted pod: my-dae-xnp6q
Normal SuccessfulCreate 12s daemonset-controller Created pod: my-dae-zscbh
[root@master01 ~]# kubectl rollout history daemonset my-dae
daemonset.apps/my-dae
REVISION CHANGE-CAUSE
1 <none>
2 kubectl set image daemonset.apps my-dae nginx=nginx:1.16.1 --record=true
回滚参数:
strategy:
rollingUpdate:
maxSurge: 25% 初识创建的pod 这个值调的越大,副本更新速度越快
maxUnavailable: 25% 初识删除的pod 这个值越小,越能保证服务稳定,更新越平滑
daemonset一般做为代理程序和单机agent使用
本文链接:
/archives/daemonset
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
Emporer-Linux!
喜欢就支持一下吧