1、在节点上配置kubelet托管启动一个pod(配置一个静态Pod)
• 节点:k8s-node1
• pod名称:web
• 镜像:nginx
1,查看 静态Pod管理目录 vim /var/lib/kubelet/config.yaml staticPodPath: /etc/kubernetes/manifests 2,cd 到这个目录中创建一个Pod 描述文件 [root@node01 ~]# cd /etc/kubernetes/manifests/ [root@node01 manifests]# vim web-pod.yaml
apiVersion: v1 kind: Pod metadata: name: web labels: role: myrole spec: containers: - name: web image: nginx ports: - name: web containerPort: 80 protocol: TCP
3,保存退出后,可以在主节点上看到静态Pod已经被node01节点的kubelet发现并启动 [root@master01 ~]# kubectl get pod -A NAMESPACE NAME READY STATUS RESTARTS AGE cka web2 1/1 Running 0 3d18h default my-pod 2/2 Running 0 3d4h default nginx-deployment-66b6c48dd5-9xmhp 1/1 Running 0 26h default nginx-deployment-66b6c48dd5-fkz4l 1/1 Running 0 26h default nginx-deployment-66b6c48dd5-w6ss6 1/1 Running 0 26h default web-node01 1/1 Running 0 44s kube-system calico-kube-controllers-97769f7c7-9d7j4 1/1 Running 0 3d21h
2、向pod中添加一个init容器,init容器创建一个空文件,如果该空文件没有被检测到pod退出
• pod名称:web
vim initContainer.yaml
apiVersion: v1 kind: Pod metadata: name: web spec: containers: - name: web-container image: nginx # init容器镜像不能和普通镜像重复 volumeMounts: - mountPath: /tmp name: tmp-volume livenessProbe: # 配置一个健康检查策略 exec: command: - cat - /tmp/healthy initialDelaySeconds: 5 periodSeconds: 5 initContainers: - name: init-container image: busybox args: # init 容器事先在共享卷中创建一个健康检查文件 - /bin/sh - -c - touch /tmp/healthy && sleep 50 volumeMounts: - mountPath: /tmp name: tmp-volume volumes: # 创建一个共享卷 - name: tmp-volume emptyDir: {}
3、创建一个deployment 副本数 3,然后滚动更新镜像版本,并记录这个更新记录,最后再回滚到上一个版本
• 名称:nginx
• 镜像版本:1.16
• 更新镜像版本:1.17
[root@master01 ~]# apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.16 ports: - containerPort: 80
4、给web deployment扩容副本数为3
[root@master01 ~]# kubectl scale --replicas=3 deploy nginx-deployment deployment.apps/nginx-deployment scaled
5、创建一个pod,其中运行着nginx、redis、memcached、consul 4个容器
6、把deployment输出json文件,再删除创建的deployment
7、生成一个deployment yaml文件保存到/opt/deploy.yaml
• 名称:web
• 标签:app_env_stage=dev
[root@master01 ~]# kubectl get deployment -o yaml > /opt/deploy.yaml
浙公网安备 33010602011771号