k8s-----13、controller-DaemonSet

部署守护进程DaemonSet

  • 1、部署

1、部署

  • 在每个node上运行一个pod,新加入的node也同样运行在一个pod 里面
  • 示例:在每个Node节点安装数据采集工具filebeart
[root@master controlleryaml]# cat ds.yaml 
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: ds-test 
  labels:
    app: filebeat
spec:
  selector:
    matchLabels:
      app: filebeat
  template:
    metadata:
      labels:
        app: filebeat
    spec:
      containers:
      - name: logs
        image: nginx
        ports:
        - containerPort: 80
        volumeMounts:
        - name: varlog
          mountPath: /tmp/log
      volumes:
      - name: varlog
        hostPath:
          path: /var/log
[root@master controlleryaml]# kubectl apply -f ds.yaml
[root@master controlleryaml]# kubectl get pods
NAME                  READY   STATUS    RESTARTS   AGE
ds-test-jkhh5         1/1     Running   0          29s
ds-test-vd5np         1/1     Running   0          29s
[root@master controlleryaml]# kubectl get pods -o wide   #node1和node2都进行了部署
NAME                  READY   STATUS    RESTARTS   AGE     IP            NODE    NOMINATED NODE   READINESS GATES
ds-test-jkhh5         1/1     Running   0          73s     10.244.1.25   node1   <none>           <none>
ds-test-vd5np         1/1     Running   0          73s     10.244.2.20   node2   <none>           <none>
[root@master controlleryaml]# kubectl exec -it ds-test-jkhh5 bash   ##进入node1下的exec
[root@master controlleryaml]# kubectl exec -it ds-test-vd5np bash   ##进入node2下的exec
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
root@ds-test-jkhh5:/# ls    
bin   dev		   docker-entrypoint.sh  home  lib64  mnt  proc  run   srv  tmp  var
boot  docker-entrypoint.d  etc			 lib   media  opt  root  sbin  sys  usr
root@ds-test-jkhh5:/# cd tmp/log/   ##内容是一致的
root@ds-test-jkhh5:/tmp/log# ls

你可能感兴趣的:(k8s新学习目录,kubernetes,容器,云原生)