k8s—控制器DaemonSet

一、daemonset

        DaemonSet 确保全部(或者某些)节点上运⾏⼀个 Pod 的副本。当有节点加⼊集群时,会为他们新增⼀个 Pod。当有节点从集群移除时,这些 Pod 也会被回收。删除 DaemonSet 将会删除它创建的所有 Pod;

        DaemonSet 中的 Pod 可以使⽤ hostPort,从⽽可以通过节点 IP 访问到 Pod;因为DaemonSet模式下Pod不会被调度到其他节点。使⽤示例如下:

ports:
    - name: httpd
      containerPort: 80
        #除⾮绝对必要,否则不要为 Pod 指定 hostPort 。 将 Pod 绑定到 hostPort 时,它会限制 Pod 可以调度的位置数; DaemonSet 除外
        #⼀般情况下 containerPort hostPort 值相同
      hostPort: 8090         # 可以通过宿主机 +hostPort 的⽅式访问该 Pod 。例如: pod / 调度到了k8s-node2 192.168.22.138 】,那么该 Pod 可以通过192.168.22.138:8090 ⽅式进⾏访问
      protocol: TCP
 二、DaemonSet示例
1.创建daemonset—编写yaml文件并应用

[root@k8s-master daemonset]# vim nginx-daemonset.yaml

[root@k8s-master daemonset]# cat nginx-daemonset.yaml 
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: nginx-daemonset
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: daocloud.io/library/nginx:1.12.0-alpine
        ports:
        - name: nginx
          containerPort: 80
          hostPort: 8090
          protocol: TCP

[root@k8s-master daemonset]# kubectl apply -f nginx-daemonset.yaml 
daemonset.apps/nginx-daemonset created
[root@k8s-master daemonset]# kubectl get ds
NAME              DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
nginx-daemonset   2         2         2       2            2           <none>          20s

 2.测试结果
        使用node节点的IP+8090端口即可访问;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值