java系统找不到指定文件怎么解决
262
2022-10-21
K8S基础:通过多种方式管理Pod
1、kubectl修改pod nginx默认页面
#命令行进入pod
[root@master server]# kubectl run mynginx --image=nginx
pod/mynginx created
[root@master server]# kubectl get pod -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mynginx 1/1 Running 0 3m3s 10.233.82.20 node01
2、多容器运行在同一个Pod
#创建yaml文件
[root@master server]# vim myapp.yaml
apiVersion: v1
kind: Pod
metadata:
labels:
run: myapp
name: myapp
#定义pod运行的容器
spec:
containers:
- image: nginx
name: nginx01
- image: tomcat:8.5.68
name: tomcat
#通过yaml文件创建多容器pod
[root@master server]# kubectl apply -f myapp.yaml
pod/myapp created
[root@master server]# kubectl get pod
NAME READY STATUS RESTARTS AGE
myapp 2/2 Running 0 93s
#查看pod创建详细信息、以及容器分配的信息
[root@master server]# kubectl describe pod myapp
Name: myapp
Namespace: default
Priority: 0
Node: master/172.18.0.2
Start Time: Wed, 13 Apr 2022 12:01:48 +0800
Labels: run=myapp
Annotations: cni.projectcalico.org/containerID: ac4ad7372e6bbeca7fa56f24fdd912d9fb3050a62a12658a916e7adaefb194f6
cni.projectcalico.org/podIP: 10.233.70.12/32
cni.projectcalico.org/podIPs: 10.233.70.12/32
Status: Running
IP: 10.233.70.12
IPs:
IP: 10.233.70.12
Containers:
nginx01:
Container ID: docker://47f75dbe49635a90af2915eb7bfedcd7dcc7c7b0e892a08e73d367814f618bf9
Image: nginx
Image ID: docker-pullable://nginx@sha256:2275af0f20d71b293916f1958f8497f987b8d8fd8113df54635f2a5915002bf1
Port:
3、deployment管理pod
#创建pod放在新的deployment里 [root@master server]# kubectl create deployment mytomcat --image=tomcat:8.5.68 deployment.apps/mytomcat created [root@master server]# kubectl get pod NAME READY STATUS RESTARTS AGE mytomcat-6f5f895f4f-t9fh2 1/1 Running 0 4m15s #删除pod演示宕机操作 [root@master server]# kubectl delete pod mytomcat-6f5f895f4f-t9fh2 pod "mytomcat-6f5f895f4f-t9fh2" deleted [root@master server]# kubectl get pod NAME READY STATUS RESTARTS AGE mytomcat-6f5f895f4f-95hjs 1/1 Running 0 3s [root@master server]# #删除deployment,彻底删除pod [root@master server]# kubectl get pod NAME READY STATUS RESTARTS AGE mytomcat-6f5f895f4f-95hjs 1/1 Running 0 3s [root@master server]# kubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE mytomcat 1/1 1 1 7m31s [root@master server]# kubectl delete deploy mytomcat deployment.apps "mytomcat" deleted [root@master server]# kubectl get pod No resources found in default namespace. [root@master server]#
4、通过副本数实现pod高可用
#创建3副本的pod
[root@master server]# kubectl create deploy mynginx --image=nginx --replicas=3
deployment.apps/mynginx created
[root@master server]# kubectl get pod
NAME READY STATUS RESTARTS AGE
mynginx-5b686ccd46-2mpnf 1/1 Running 0 8s
mynginx-5b686ccd46-d97p5 1/1 Running 0 8s
mynginx-5b686ccd46-t6dgt 1/1 Running 0 8s
[root@master server]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
mynginx 3/3 3 3 12s
#查看容器分布的情况
[root@master server]# kubectl get pod -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mynginx-5b686ccd46-2mpnf 1/1 Running 0 2m43s 10.233.82.21 node01
5、通过deployment实现扩缩容
#扩容
[root@master server]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
mynginx 3/3 3 3 6m37s
[root@master server]# kubectl get pod
NAME READY STATUS RESTARTS AGE
mynginx-5b686ccd46-2mpnf 1/1 Running 0 6m47s
mynginx-5b686ccd46-d97p5 1/1 Running 0 6m47s
mynginx-5b686ccd46-tds4m 1/1 Running 0 2m58s
[root@master server]# kubectl scale deploy/mynginx --replicas=5
deployment.apps/mynginx scaled
[root@master server]# kubectl get pod -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mynginx-5b686ccd46-2mpnf 1/1 Running 0 8m25s 10.233.82.21 node01
6、pod的版本控制
#滚动更新,指定镜像更新deployment里的容器版本
[root@master ~]# kubectl set image deploy/mynginx nginx=nginx:1.16.1 --record
deployment.apps/mynginx image updated
#每秒刷新pod状态,查看版本更新过程
[root@master server]# watch -n 1 kubectl get pod -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mynginx-5b686ccd46-4cwr8 1/1 Running 0 3m7s 10.233.82.45 node01
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~