Centos7部署kubernetes测试k8s应用(九)
1、创建一个deployment
[root@linux-node1 ~]# kubectl run net-test --image=alpine --replicas=2 sleep 360000
deployment.apps "net-test" created
2、查看获取IP情况
[root@linux-node1 ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
net-test-5767cb94df-5h8b6 1/1 Running 0 3m 10.2.79.2 192.168.43.23
net-test-5767cb94df-n5mcr 1/1 Running 0 3m 10.2.74.2 192.168.43.22
3、测试连通性
ping 10.2.79.2
4、测试nginx
[root@linux-node1 ~]# vim nginx-deployment.yaml
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.10.3
ports:
- containerPort: 80
5、创建nginx-deploymen
[root@linux-node1 ~]# kubectl create -f nginx-deployment.yaml
deployment.apps "nginx-deployment" created
6、查看deploymen
[root@linux-node1 ~]# kubectl get deployment
7、查看deploymen详细信息
[root@linux-node1 ~]# kubectl describe deployment
8、查看单个副本的详细信息
[root@linux-node1 ~]# kubectl describe pod nginx-deployment-75d56bb955-4vsns
9、查看pod
[root@linux-node1 ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
net-test-5767cb94df-5h8b6 1/1 Running 0 11m 10.2.79.2 192.168.43.23
net-test-5767cb94df-n5mcr 1/1 Running 0 11m 10.2.74.2 192.168.43.22
nginx-deployment-75d56bb955-4vsns 1/1 Running 0 4m 10.2.74.3 192.168.43.22
nginx-deployment-75d56bb955-l97zv 1/1 Running 0 4m 10.2.79.3 192.168.43.23
nginx-deployment-75d56bb955-wlfp2 1/1 Running 0 4m 10.2.79.4 192.168.43.23
10、测试pod访问
[root@linux-node1 ~]# curl --head http://10.2.74.3
11、更新deployment
[root@linux-node1 ~]# kubectl set image deployment/nginx-deployment nginx=nginx:1.12.2 --record
deployment.apps "nginx-deployment" image updated
12、查看更新后的deployment
[root@linux-node1 ~]# kubectl get deployment -o wide
13、回滚到上一个版本
[root@linux-node1 ~]# kubectl rollout undo deployment/nginx-deployment
14、创建service
[root@linux-node1 ~]# vim nginx-service.yaml
kind: Service
apiVersion: v1
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
[root@linux-node1 ~]# kubectl create -f nginx-service.yaml
service "nginx-service" created
15、可以看到已经实现了负载均衡
[root@linux-node2 ssl]# ipvsadm -LN
-LN: unknown option
[root@linux-node2 ssl]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 10.1.0.1:443 rr persistent 10800
-> 192.168.43.21:6443 Masq 1 0 0
TCP 10.1.185.150:80 rr
-> 10.2.74.3:80 Masq 1 0 0
-> 10.2.74.5:80 Masq 1 0 0
-> 10.2.79.3:80 Masq 1 0 0
别在该奋斗的年纪,选择安逸。