0
点赞
收藏
分享

微信扫一扫

k8s学习-DaemonSet(模板、创建、更新、回滚、删除等)


目录

  • ​​概念​​
  • ​​模板​​
  • ​​实战​​
  • ​​创建​​
  • ​​更新​​
  • ​​回滚​​
  • ​​回滚到上一版本​​
  • ​​回滚到指定版本​​
  • ​​删除​​
  • ​​参考​​

概念

DaemonSet:守护进程集,在kubectl中缩写为ds,在所有节点或者是匹配的节点上都部署一个Pod,当有节点加入集群时, 也会为他们新增一个 Pod 。
使用DaemonSet的场景

  • 运行集群存储的daemon,比如ceph或者glusterd
  • 节点的CNI网络插件:calico
  • 节点日志的收集:fluentd或者是filebeat
  • 节点的监控:node exporter
  • 服务暴露:部署一个ingress nginx

日志和监控比较经典。

我们安装集群的时候,calico和kube-proxy是daemonset的方式启动的。

k8s学习-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.15.2
imagePullPolicy: IfNotPresent
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
terminationGracePeriodSeconds: 30

相较于Deployment,DaemonSet没有副本数,因为他是一个节点启动一个,容器。

实战

创建

命令

kubectl create -f ds-test.yaml

结果

k8s学习-DaemonSet(模板、创建、更新、回滚、删除等)_kubernetes_02


查看全部的yaml

命令

>

结果

apiVersion: apps/v1
kind: DaemonSet
metadata:
annotations:
deprecated.daemonset.template.generation: "1"
creationTimestamp: "2022-06-26T17:16:22Z"
generation: 1
labels:
app: nginx
name: nginx
namespace: killer
resourceVersion: "146918"
selfLink: /apis/apps/v1/namespaces/killer/daemonsets/nginx
uid: 50c28ba2-aa39-4fa6-b1c1-97d4b2c7c8f9
spec:
revisionHistoryLimit: 10
selector:
matchLabels:
app: nginx
template:
metadata:
creationTimestamp: null
labels:
app: nginx
spec:
containers:
- image: nginx:1.15.2
imagePullPolicy: IfNotPresent
name: nginx
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
updateStrategy:
rollingUpdate:
maxUnavailable: 1
type: RollingUpdate
status:
currentNumberScheduled: 1
desiredNumberScheduled: 1
numberAvailable: 1
numberMisscheduled: 0
numberReady: 1
observedGeneration: 1
updatedNumberScheduled: 1

不同于deployment的strategy,ds的回滚策略字段和sts的一样,是updateStrategy。

更新

以更新镜像为例
命令

kubectl set image  ds nginx nginx=nginx:1.15.3 -n killer --record

结果

k8s学习-DaemonSet(模板、创建、更新、回滚、删除等)_运维_03

回滚

再更新几次之后,查看下更新记录
命令

kubectl rollout history

结果

k8s学习-DaemonSet(模板、创建、更新、回滚、删除等)_ico_04

回滚到上一版本

命令

kubectl rollout undo ds nginx -n killer

截图

k8s学习-DaemonSet(模板、创建、更新、回滚、删除等)_回滚_05

回滚到指定版本

命令

kubectl rollout history ds nginx --revision=2

截图

k8s学习-DaemonSet(模板、创建、更新、回滚、删除等)_nginx_06

删除

命令

kubectl delete ds nginx -n killer

结果

k8s学习-DaemonSet(模板、创建、更新、回滚、删除等)_运维_07

更多k8s相关内容,请看文章:​​k8s学习-思维导图与学习笔记​​

参考

​​k8s-DaemonSet​​


举报

相关推荐

0 条评论