kubernet 在centos 搭建的集群上的实践 -- 《一》

1> 部署应用

[root@k8s-master ~]# kubectl run nginx --image=nginx:1.7.9

deployment "nginx" created
[root@k8s-master ~]# kubectl get deploy
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE

nginx     1         1         1            1           42s

2>查看应用

[root@k8s-master ~]# kubectl get deploy -o wide
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE       CONTAINERS   IMAGES        SELECTOR

nginx     1         1         1            1           55s       nginx        nginx:1.7.9   run=nginx

3> 查看pod具体信息

[root@k8s-master ~]# kubectl get pod -o wide
NAME                     READY     STATUS    RESTARTS   AGE       IP            NODE
nginx-665ff4c6f7-q76rg   1/1       Running   0          1m        10.244.1.25   huleib.eng.platformlab.ibm.com

4> 暴露部署服务:

[root@k8s-master ~]# kubectl expose deploy nginx --type=NodePort --name=nginx-test --port=80

service "nginx-test" exposed

[root@k8s-master ~]# kubectl expose deploy nginx --type=NodePort --name=nginx --port=80

service "nginx" exposed

5> 验证部署的服务为什么基于同一个pod

[root@k8s-master ~]# kubectl get ep
NAME         ENDPOINTS            AGE
kubernetes   9.111.252.196:6443   3d
nginx        10.244.1.25:80       8s
nginx-test   10.244.1.25:80       40s
testa        10.244.1.25:80       3m
[root@k8s-master ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1                443/TCP        3d
nginx        NodePort    10.97.73.87              80:30031/TCP   35s
nginx-test   NodePort    10.102.130.239           80:31098/TCP   1m
testa        NodePort    10.111.157.251           80:30690/TCP   3m

6> 删除服务

[root@k8s-master ~]# kubectl delete svc  testa

service "testa" deleted
[root@k8s-master ~]# kubectl get ep
NAME         ENDPOINTS            AGE
kubernetes   9.111.252.196:6443   3d
nginx        10.244.1.25:80       1m
nginx-test   10.244.1.25:80       1m

7> 拓展/扩大RS 的数量(副本数)

[root@k8s-master ~]# kubectl scale deploy nginx --replicas 3

deployment "nginx" scaled
[root@k8s-master ~]# kubectl get ep
NAME         ENDPOINTS                                      AGE
kubernetes   9.111.252.196:6443                             3d
nginx        10.244.1.25:80,10.244.1.26:80,10.244.1.27:80   13m
nginx-test   10.244.1.25:80,10.244.1.26:80,10.244.1.27:80   14m
[root@k8s-master ~]# kubectl get po
NAME                     READY     STATUS    RESTARTS   AGE
nginx-665ff4c6f7-7npds   1/1       Running   0          42s
nginx-665ff4c6f7-hx86p   1/1       Running   0          42s
nginx-665ff4c6f7-q76rg   1/1       Running   0          38m
[root@k8s-master ~]# kubectl get po -o  wide
NAME                     READY     STATUS    RESTARTS   AGE       IP            NODE
nginx-665ff4c6f7-7npds   1/1       Running   0          1m        10.244.1.27   huleib.eng.platformlab.ibm.com
nginx-665ff4c6f7-hx86p   1/1       Running   0          1m        10.244.1.26   huleib.eng.platformlab.ibm.com
nginx-665ff4c6f7-q76rg   1/1       Running   0          39m       10.244.1.25   huleib.eng.platformlab.ibm.com

8> 回滚验证:

[root@k8s-master ~]# kubectl set image deploy nginx nginx=ngnix:1.9.1

deployment "nginx" image updated
[root@k8s-master ~]# kubectl rollout status nginx
the server doesn't have a resource type "nginx"
[root@k8s-master ~]# kubectl rollout status deploy nginx
Waiting for rollout to finish: 2 out of 3 new replicas have been updated... >>>>>>>>>>>>>>>>>> 由于镜像问题,不能正常升级,这点的确在生产环境中的不down 机, 滚动升级就太爽了。。。。。

[root@k8s-master ~]# kubectl rollout history  deploy nginx
deployments "nginx"
REVISION  CHANGE-CAUSE
1        
2        


[root@k8s-master ~]# kubectl get rs
NAME               DESIRED   CURRENT   READY     AGE
nginx-665ff4c6f7   2         2         2         45m
nginx-76c54977d9   2         2         0         4m
[root@k8s-master ~]# kubectl describe rs nginx-76c54977d9
Name:           nginx-76c54977d9
Namespace:      default
Selector:       pod-template-hash=3271053385,run=nginx
Labels:         pod-template-hash=3271053385
                run=nginx
Annotations:    deployment.kubernetes.io/desired-replicas=3
                deployment.kubernetes.io/max-replicas=4
                deployment.kubernetes.io/revision=2
Controlled By:  Deployment/nginx
Replicas:       2 current / 2 desired
Pods Status:    0 Running / 2 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  pod-template-hash=3271053385
           run=nginx
  Containers:
   nginx:
    Image:        ngnix:1.9.1
    Port:        
    Environment: 
    Mounts:      
  Volumes:       
Events:
  Type    Reason            Age   From                   Message
  ----    ------            ----  ----                   -------
  Normal  SuccessfulCreate  4m    replicaset-controller  Created pod: nginx-76c54977d9-4z5rj
  Normal  SuccessfulCreate  4m    replicaset-controller  Created pod: nginx-76c54977d9-dz76m
[root@k8s-master ~]# kubectl get pod
NAME                     READY     STATUS             RESTARTS   AGE
nginx-665ff4c6f7-hx86p   1/1       Running            0          8m
nginx-665ff4c6f7-q76rg   1/1       Running            0          46m
nginx-76c54977d9-4z5rj   0/1       ImagePullBackOff   0          4m
nginx-76c54977d9-dz76m   0/1       ImagePullBackOff   0          4m
[root@k8s-master ~]# kubectl describe nginx-76c54977d9-4z5rj
the server doesn't have a resource type "nginx-76c54977d9-4z5rj"
[root@k8s-master ~]# kubectl describe pod  nginx-76c54977d9-4z5rj
Name:           nginx-76c54977d9-4z5rj
Namespace:      default
Node:           huleib.eng.platformlab.ibm.com/9.111.252.241
Start Time:     Tue, 12 Dec 2017 02:39:32 -0500
Labels:         pod-template-hash=3271053385
                run=nginx
Annotations:    kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"default","name":"nginx-76c54977d9","uid":"5f94d64b-df0f-11e7-85ac-62dd8a7f1900","...
Status:         Pending
IP:             10.244.1.28
Created By:     ReplicaSet/nginx-76c54977d9
Controlled By:  ReplicaSet/nginx-76c54977d9
Containers:
  nginx:
    Container ID:   
    Image:          ngnix:1.9.1
    Image ID:       
    Port:          
    State:          Waiting
      Reason:       ImagePullBackOff
    Ready:          False
    Restart Count:  0
    Environment:   
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-dfvzj (ro)
Conditions:
  Type           Status
  Initialized    True
  Ready          False
  PodScheduled   True
Volumes:
  default-token-dfvzj:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-dfvzj
    Optional:    false
QoS Class:       BestEffort
Node-Selectors: 
Tolerations:     node.alpha.kubernetes.io/notReady:NoExecute for 300s
                 node.alpha.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason                 Age                      From                                     Message
  ----     ------                 ----                     ----                                     -------
  Normal   Scheduled              5m                       default-scheduler                        Successfully assigned nginx-76c54977d9-4z5rj to huleib.eng.platformlab.ibm.com
  Normal   SuccessfulMountVolume  3m                       kubelet, huleib.eng.platformlab.ibm.com  MountVolume.SetUp succeeded for volume "default-token-dfvzj"
  Normal   Pulling                2m (x4 over 3m)          kubelet, huleib.eng.platformlab.ibm.com  pulling image "ngnix:1.9.1"
  Warning  Failed                 2m (x4 over 3m)          kubelet, huleib.eng.platformlab.ibm.com  Failed to pull image "ngnix:1.9.1": rpc error: code = Unknown desc = Error response from daemon: repository ngnix not found: does not exist or no pull access
  Normal   BackOff                1m (x6 over 3m)          kubelet, huleib.eng.platformlab.ibm.com  Back-off pulling image "ngnix:1.9.1"
  Warning  FailedSync             (x24 over 3m)  kubelet, huleib.eng.platformlab.ibm.com  Error syncing pod


9> 取消回滚

[root@k8s-master ~]# kubectl rollout undo deploy nginx

deployment "nginx" rolled back
[root@k8s-master ~]# kubectl get rs
NAME               DESIRED   CURRENT   READY     AGE
nginx-665ff4c6f7   3         3         3         48m
nginx-76c54977d9   0         0         0         6m
[root@k8s-master ~]# kubectl get rs -o wide
NAME               DESIRED   CURRENT   READY     AGE       CONTAINERS   IMAGES        SELECTOR
nginx-665ff4c6f7   3         3         3         48m       nginx        nginx:1.7.9   pod-template-hash=2219907293,run=nginx
nginx-76c54977d9   0         0         0         7m        nginx        ngnix:1.9.1   pod-template-hash=3271053385,run=nginx
[root@k8s-master ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1                443/TCP        3d
nginx        NodePort    10.97.73.87              80:30031/TCP   24m
nginx-test   NodePort    10.102.130.239           80:31098/TCP   25m
[root@k8s-master ~]# kubectl get pod
NAME                     READY     STATUS    RESTARTS   AGE
nginx-665ff4c6f7-92wc7   1/1       Running   0          2m
nginx-665ff4c6f7-hx86p   1/1       Running   0          11m
nginx-665ff4c6f7-q76rg   1/1       Running   0          50m
[root@k8s-master ~]# kubectl get ep
NAME         ENDPOINTS                                      AGE
kubernetes   9.111.252.196:6443                             3d
nginx        10.244.1.25:80,10.244.1.26:80,10.244.1.30:80   25m
nginx-test   10.244.1.25:80,10.244.1.26:80,10.244.1.30:80   26m
[root@k8s-master ~]# kubectl delete pod nginx-665ff4c6f7-q76rg
pod "nginx-665ff4c6f7-q76rg" deleted
[root@k8s-master ~]# kubectl get ep
NAME         ENDPOINTS                                      AGE
kubernetes   9.111.252.196:6443                             3d
nginx        10.244.1.26:80,10.244.1.30:80,10.244.1.31:80   26m
nginx-test   10.244.1.26:80,10.244.1.30:80,10.244.1.31:80   27m
[root@k8s-master ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1                443/TCP        3d
nginx        NodePort    10.97.73.87              80:30031/TCP   28m
nginx-test   NodePort    10.102.130.239           80:31098/TCP   29m
[root@k8s-master ~]# kubectl get pod
NAME                     READY     STATUS    RESTARTS   AGE
nginx-665ff4c6f7-5qstw   1/1       Running   0          3m
nginx-665ff4c6f7-92wc7   1/1       Running   0          7m
nginx-665ff4c6f7-hx86p   1/1       Running   0          17m


你可能感兴趣的:(kubernet 在centos 搭建的集群上的实践 -- 《一》)