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.