dameonset 重启_K8s - Kubernetes使用详解3(运行DaemonSet样例)

三、运行 DaemonSet

1,DaemonSet 与 Deployment 的区别

Deployment 部署的副本 Pod 会分布在各个 Node 上,每个 Node 都可能运行好几个副本。

DaemonSet 的不同之处在于:每个 Node 上最多只能运行一个副本。

2,DaemonSet 的典型应用场景

在集群的每个节点上运行存储 Daemon,比如:glusterd 或 ceph。

在每个节点上运行日志收集 Daemon,比如:flunentd 或 logstash。

在每个节点上运行监控 Daemon,比如:Prometheus Node Exporter或 collectd。

3,k8s 自己的 DaemonSet

(1)其实 Kubernetes 自己就在用 DaemonSet 运行系统组件。执行如下命令查看:

kubectl get daemonset --namespace=kube-system

(2)DaemonSet kube-flannel-ds 和 kube-proxy 分别负责每个节点上运行 flannel 和 kube-proxy  组件。由于我这里是三节点的集群,所以它们各有 3 个副本。

4,运行自己的 DaemonSet

(1)下面以 Prometheus Node Exporter 为例演示如何运行自己的 DaemonSet。

Prometheus 是流行的系统监控方案,Node Exporter是 Prometheus 的 agent,以 Daemon 的形式运行在每个被监控节点上。

(2)如果是直接在 Docker 中运行 Node Exporter容器,命令如下:

docker run -d \

-v "/proc:/host/proc" \

-v "/sys:/host/sys" \

-v "/:/rootfs" \

--net=host \

prom/node-exporter \

--path.procfs /host/proc \

--path.sysfs /host/sys \

--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"

(3)我们将其转换为 DaemonSet 的 YAML 配置文件node_exporter.yml,内容如下:

apiVersion: extensions/v1beta1

kind: DaemonSet

metadata:

name: node-exporter-daemonset

spec:

template:

metadata:

labels:

app: promtheus

spec:

hostNetwork: true # 直接使用Host网络

containers:

- image: prom/node-exporter

name: node-exporter

imagePullPolicy: IfNotPresent

command: # 设置容器的启动命令

- /bin/node_exporter

- --path.procfs

- /host/proc

- --path.sysfs

- /host/sys

- --collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"

volumeMounts: # 通过 Volume 将 Host 路径 /proc、/sys 和 / 映射到容器中

- name: proc

mountPath: /host/proc

- name: sys

mountPath: /host/sys

- name: root

mountPath: /host/rootfs

volumes:

- name: proc

hostPath:

path: /proc

- name: sys

hostPath:

path: /sys

- name: root

hostPath:

path: /

(4)然后执行 kubectl apply命令进行部署即可,部署后在每一个节点上都会运行了一个 node exporter Pod。

kubectl apply -f node_exporter.yml

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值