创建第一kubernetes应用以及基本操作(六)

1.创建一个测试用的deployment

kubectl run net-test --image=alpine --replicas=2 sleep 360000

2、查看获取IP情况

[root@linux ~]# kubectl get pod -o wide
NAME                                READY     STATUS    RESTARTS   AGE       IP           NODE
net-test-5767cb94df-8vvqv           1/1       Running   0          37m       10.2.43.2    192.168.56.12
net-test-5767cb94df-fzklz           1/1       Running   0          37m       10.2.43.4    192.168.56.12
net-test1-8557578bc-mdwpf           1/1       Running   0          36m       10.2.91.7    192.168.56.13
net-test1-8557578bc-p946b           1/1       Running   0          36m       10.2.91.6    192.168.56.13
nginx-65899c769f-27h4q              1/1       Running   0          37m       10.2.43.3    192.168.56.12
nginx-65899c769f-5449m              1/1       Running   0          37m       10.2.43.12   192.168.56.12
nginx-65899c769f-mkvpg              1/1       Running   0          37m       10.2.43.6    192.168.56.12
nginx-65899c769f-vl7nb              1/1       Running   0          37m       10.2.43.8    192.168.56.12
nginx-65899c769f-xg8d2              1/1       Running   0          37m       10.2.43.7    192.168.56.12
nginx-deployment-7498dc98f8-54hq2   1/1       Running   0          5m        10.2.91.9    192.168.56.13
nginx-deployment-7498dc98f8-msqmb   1/1       Running   0          6m        10.2.91.8    192.168.56.13
nginx-deployment-7498dc98f8-whwz6   1/1       Running   0          5m        10.2.91.10   192.168.56.13
nginx-test-6b8f899d7d-bntc8         1/1       Running   0          37m       10.2.43.11   192.168.56.12

 3、查看deployment

[root@linux ~]# kubectl  get deployment
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
net-test           2         2         2            2           22d
net-test1          2         2         2            2           37m
nginx              5         5         5            5           41m
nginx-deployment   3         3         3            3           51m
nginx-test         1         1         1            1           1d

 

4、查看deployment详情

kubectl  describe deployment  nginx

 

 5、查看pod详情

kubectl  describe pod   pod名称

如:kubectl  describe pod nginx-test-6b8f899d7d-bntc8

 

6、跟新deployment版本

kubectl  set image deployment/nginx-deployment  nginx=nginx:1.12.2 --record

--record 表示记录日志,用于做回滚

 

 

以上每次执行后ip都会变化,在正常业务中是不满足我们的业务需求的,需要一个vip实现。这就用到service 的ip  也就是vip

 

7、编写一个service的yaml文件

vim  nginx-service.yaml
kind: Service apiVersion: v1 metadata: name: nginx
-service01 spec: selector: app: nginx ports: - protocol: TCP port: 80 targetPort: 80

 

8、创建service

kubectl  create -f nginx-service.yaml 

 

9、查看service

[root@linux ~]# kubectl  get service
NAME            TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
kubernetes      ClusterIP   10.1.0.1      <none>        443/TCP        23d
nginx-service   NodePort    10.1.232.55   <none>        80:30080/TCP   1d

 

10、测试

[root@linux ~]# curl  --head http://10.1.232.55
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Fri, 29 Mar 2019 08:13:03 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 11 Jul 2017 13:29:18 GMT
Connection: keep-alive
ETag: "5964d2ae-264"
Accept-Ranges: bytes

 

11、查看service vip代理的后端

[root@linux ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.56.12:30080 rr persistent 10800
  -> 10.2.91.8:80                 Masq    1      0          0         
  -> 10.2.91.9:80                 Masq    1      0          0         
  -> 10.2.91.10:80                Masq    1      0          0         
TCP  10.1.0.1:443 rr persistent 10800
  -> 192.168.56.11:6443           Masq    1      0          0         
TCP  10.1.189.235:80 rr
  -> 10.2.91.8:80                 Masq    1      0          0         
  -> 10.2.91.9:80                 Masq    1      0          0         
  -> 10.2.91.10:80                Masq    1      0          0         
TCP  10.1.232.55:80 rr persistent 10800
  -> 10.2.91.8:80                 Masq    1      0          0         
  -> 10.2.91.9:80                 Masq    1      0          0         
  -> 10.2.91.10:80                Masq    1      0          1         
TCP  10.2.43.0:30080 rr persistent 10800
  -> 10.2.91.8:80                 Masq    1      0          0         
  -> 10.2.91.9:80                 Masq    1      0          0         
  -> 10.2.91.10:80                Masq    1      0          0         
TCP  10.2.43.1:30080 rr persistent 10800
  -> 10.2.91.8:80                 Masq    1      0          0         
  -> 10.2.91.9:80                 Masq    1      0          0         
  -> 10.2.91.10:80                Masq    1      0          0         
TCP  127.0.0.1:30080 rr persistent 10800
  -> 10.2.91.8:80                 Masq    1      0          0         
  -> 10.2.91.9:80                 Masq    1      0          0         
  -> 10.2.91.10:80                Masq    1      0          0         

 

posted @ 2019-08-21 14:38  凉生墨客  阅读(475)  评论(0编辑  收藏  举报