14.k8s-helloword验证集群

k8s-helloword验证集群

使用nginx镜像验证

docker pull nginx:1.19.8
docker tag nginx:1.19.8 harbor.hzwod.com/public/nginx:1.19.8
docker push harbor.hzwod.com/public/nginx:1.19.8

每个node上启动nginx容器

使用DaemonSet controller在每个node上都启动一个nginx

DaemonSet 确保全部(或者一些)Node 上运行一个 Pod 的副本。当有 Node 加入集群时,也会为他们新增一个 Pod 。当有 Node 从集群移除时,这些 Pod 也会被回收。删除 DaemonSet 将会删除它创建的所有 Pod。 使用 DaemonSet 的一些典型用法:

  • 运行集群存储 daemon,例如在每个 Node 上运行 glusterd、ceph。
  • 在每个 Node 上运行日志收集 daemon,例如filebeat、logstash。
  • 在每个 Node 上运行监控 daemon,例如 Prometheus Node Exporter、collectd、Datadog 代理、Zabbix Agent。
DaemonSet controller部署nginx容器
  • 创建DaemonSet类型的资源文件
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: harbor.hzwod.com/public/nginx:1.19.8
        ports:
        - containerPort: 80
  • 使用kubectl创建DaemonSet
[root@node21 ~]# kubectl create -f nginx-ds.yaml 
daemonset.apps/nginx-daemonset created
  • 查看pod
[root@node21 ~]# kubectl get ds
NAME              DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
nginx-daemonset   2         2         2       2            2           <none>          22s
[root@node21 ~]# kubectl get pod -o wide
NAME                    READY   STATUS    RESTARTS   AGE   IP            NODE           NOMINATED NODE   READINESS GATES
nginx-daemonset-c7zng   1/1     Running   0          25s   172.20.22.2   172.10.10.22   <none>           <none>
nginx-daemonset-gc4gl   1/1     Running   0          25s   172.20.21.2   172.10.10.21   <none>           <none>
  • 访问nginx
[root@node21 ~]# curl 172.20.21.2
...
<title>Welcome to nginx!</title>
...
[root@node21 ~]# curl 172.20.22.2
curl: (7) Failed connect to 172.20.22.2:80; 连接超时

node21访问不通node22上的容器,这需要后续网络插件的部署来解决跨主机通讯的问题

  • 关闭/删除DeamonSet资源
[root@node21 ~]# kubectl get ds
NAME              DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
nginx-daemonset   2         2         2       2            2           <none>          21m
[root@node21 ~]# kubectl delete ds nginx-daemonset
daemonset.apps "nginx-daemonset" deleted
[root@node21 ~]# kubectl get ds
No resources found in default namespace.
[root@node21 ~]# kubectl get pod
No resources found in default namespace.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hzw@sirius

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值