1. <dd id="erndk"></dd>
                1. k8s實例

                  互聯網 2021/12/27 6:09:28

                  k8s實例 1. 創建一個deployment副本數為3,然后滾動更新鏡像版本,并記錄這個更新記錄,最后再回滾到上一個版本2. 給一個應用擴容副本數為33. 創建一個pod,其中運行著nginx、redis、mamcached4. 給一個pod創建一個service,并可以通過Cluster/NodePort訪問5. 創建deploy…

                  k8s實例

                  • 1. 創建一個deployment副本數為3,然后滾動更新鏡像版本,并記錄這個更新記錄,最后再回滾到上一個版本
                  • 2. 給一個應用擴容副本數為3
                  • 3. 創建一個pod,其中運行著nginx、redis、mamcached
                  • 4. 給一個pod創建一個service,并可以通過Cluster/NodePort訪問
                  • 5. 創建deployment和service,使用busybox容器nslookup解析service

                  1. 創建一個deployment副本數為3,然后滾動更新鏡像版本,并記錄這個更新記錄,最后再回滾到上一個版本

                  [root@master test]# cat test.yml 
                  ---
                  apiVersion: apps/v1
                  kind: Deployment
                  metadata:
                    name: test
                    labels: 
                      app: test
                  spec:
                    replicas: 3
                    selector:
                      matchLabels:
                        app: test
                    template:
                      metadata:
                        labels:
                          app: test
                      spec: 
                        containers:
                        - image: dockerimages123/httpd:v0.1
                          name: test
                          imagePullPolicy: IfNotPresent
                  
                  
                  [root@master test]# kubectl apply -f test.yml 
                  deployment.apps/test created
                  
                  [root@master haproxy]# kubectl get pod
                  NAME                    READY   STATUS    RESTARTS   AGE
                  test-85cd869cd6-7524t   1/1     Running   0          4m49s
                  test-85cd869cd6-8khgw   1/1     Running   0          4m49s
                  test-85cd869cd6-kc7fw   1/1     Running   0          4m49s
                  
                  // 滾動更新
                  [root@master haproxy]# kubectl set image deploy/test test=dockerimage123/httpd:v2.0
                  deployment.apps/test image updated
                  
                  [root@master haproxy]# kubectl get pod
                  NAME                    READY   STATUS        RESTARTS   AGE
                  test-6cfbd9b7f-5dxjk    1/1     Running       0          13s
                  test-6cfbd9b7f-8kbs8    1/1     Running       0          11s
                  test-6cfbd9b7f-sv9km    1/1     Running       0          14s
                  test-85cd869cd6-7524t   1/1     Terminating   0          9m24s
                  test-85cd869cd6-8khgw   1/1     Terminating   0          9m24s
                  test-85cd869cd6-kc7fw   1/1     Terminating   0          9m24s
                  
                  [root@master haproxy]# kubectl get pod
                  NAME                   READY   STATUS    RESTARTS   AGE
                  test-6cfbd9b7f-5dxjk   1/1     Running   0          103s
                  test-6cfbd9b7f-8kbs8   1/1     Running   0          101s
                  test-6cfbd9b7f-sv9km   1/1     Running   0          104s
                  
                  
                  [root@master haproxy]# kubectl rollout history deploy test
                  deployment.apps/test 
                  REVISION  CHANGE-CAUSE
                  1         <none>
                  2         <none>
                  3         <none>
                  
                  [root@master haproxy]# kubectl rollout history deploy test --revision=3    
                  deployment.apps/test with revision #3  //查看上一個版本的信息
                  Pod Template:
                    Labels:       app=test
                          pod-template-hash=6cfbd9b7f
                    Containers:
                     test:
                      Image:      dockerimages123/httpd:v2.0
                      Port:       <none>
                      Host Port:  <none>
                      Environment:        <none>
                      Mounts:     <none>
                    Volumes:      <none>
                    
                  [root@master haproxy]# kubectl rollout undo deploy test  //回滾到上一個版本
                  deployment.apps/test rolled back
                  
                  [root@master haproxy]# kubectl get pod
                  NAME                    READY   STATUS             RESTARTS   AGE
                  test-6cfbd9b7f-5dxjk    1/1     Running            0          32m
                  test-6cfbd9b7f-8kbs8    1/1     Running            0          32m
                  test-6cfbd9b7f-sv9km    1/1     Running            0          32m
                  

                  2. 給一個應用擴容副本數為3

                  [root@master test]# kubectl create deploy test --image nginx
                  deployment.apps/test1 created
                  
                  [root@master test]# kubectl get pod
                  test1-6d5588f8cc-4hgnt   1/1     Running             0          6m33s
                  
                  [root@master test]# kubectl get pod
                  NAME                     READY   STATUS    RESTARTS   AGE
                  test-5f6778868d-4t9xd    1/1     Running   0          2m23s
                  test1-6d5588f8cc-4hgnt   1/1     Running   0          8m51s
                  test1-6d5588f8cc-b9qsw   1/1     Running   0          49s
                  test1-6d5588f8cc-vkvh5   1/1     Running   0          49s
                  

                  3. 創建一個pod,其中運行著nginx、redis、mamcached

                  [root@master test]# cat test.yml 
                  ---
                  apiVersion: v1
                  kind: Pod
                  metadata:
                    name: test
                    labels: 
                      app: test
                  spec:
                    containers:
                    - image: nginx
                      name: nginx
                    - image: redis
                      name: redis
                    - image: memcached
                      name: memcached
                  
                  
                  
                  [root@master test]# kubectl apply -f test.yml 
                  pod/test created
                  
                  [root@master test]# kubectl get pod
                  NAME   READY   STATUS             RESTARTS   AGE
                  test3   3/3     Running            0         18m
                  
                  

                  4. 給一個pod創建一個service,并可以通過Cluster/NodePort訪問

                  [root@master test]# cat test.yml 
                  ---
                  apiVersion: v1
                  kind: Pod
                  metadata:
                    name: test
                    labels: 
                      app: test
                  spec:
                    containers:
                    - image: nginx
                      name: nginx
                  ---
                  apiVersion: v1
                  kind: Service
                  metadata:
                    name: test1
                  spec:
                    ports:
                    - port: 80
                      targetPort: 80
                      nodePort: 30001
                    selector:
                      app: test1
                    type: NodePort
                  
                  
                  [root@master test]# kubectl apply -f test.yml
                  pod/test unchanged
                  service/test created
                  
                  [root@master test]# kubectl get pod,svc
                  NAME        READY   STATUS    RESTARTS   AGE
                  pod/test   1/1     Running   0          50s
                  
                  NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
                  service/kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP        7d1h
                  service/test4        NodePort    10.110.1100.198   <none>        80:30001/TCP   50s
                  
                  [root@master test]# curl 10.110.1100.198 
                  <!DOCTYPE html>
                  <html>
                  <head>
                  <title>Welcome to nginx!</title>
                  <style>
                  
                  [root@master test]# curl 192.168.182.150:30001
                  <!DOCTYPE html>
                  <html>
                  <head>
                  <title>Welcome to nginx!</title>
                  <style>
                  

                  5. 創建deployment和service,使用busybox容器nslookup解析service

                  [root@master test]# kubectl run test2 --image busybox -- sleep 500
                  pod/test2 created
                  
                  [root@master test]# kubectl get pod
                  NAME    READY   STATUS    RESTARTS   AGE
                  test2   1/1     Running   0          22s
                  
                  [root@master test]# kubectl exec -it test2 -- /bin/sh
                  / # nslookup kubernetes
                  Server:         10.96.0.10
                  Address:        10.96.0.10:53
                  
                  Name:   kubernetes.default.svc.cluster.local
                  Address: 10.96.0.1
                  
                  *** Can't find kubernetes.svc.cluster.local: No answer
                  *** Can't find kubernetes.cluster.local: No answer
                  *** Can't find kubernetes.example.com: No answer
                  *** Can't find kubernetes.default.svc.cluster.local: No answer
                  *** Can't find kubernetes.svc.cluster.local: No answer
                  *** Can't find kubernetes.cluster.local: No answer
                  *** Can't find kubernetes.example.com: No answer
                  
                  
                  
                  隨時隨地學軟件編程-關注百度小程序和微信小程序
                  關于找一找教程網

                  本站文章僅代表作者觀點,不代表本站立場,所有文章非營利性免費分享。
                  本站提供了軟件編程、網站開發技術、服務器運維、人工智能等等IT技術文章,希望廣大程序員努力學習,讓我們用科技改變世界。
                  [k8s實例]http://www.yachtsalesaustralia.com/tech/detail-276248.html

                  贊(0)
                  關注微信小程序
                  程序員編程王-隨時隨地學編程

                  掃描二維碼或查找【程序員編程王】

                  可以隨時隨地學編程啦!

                  技術文章導航 更多>
                  掃一掃關注最新編程教程
                  国产在线拍揄自揄视频菠萝

                        1. <dd id="erndk"></dd>