learning kubernetes by minikube, 3

Goals

  1. Understand the basics of the deployment and service
  2. Create our deployment using YAML
  3. Execute our deployment using YAML
  4. Verify that the application is working as expected
  5. Scale the helloworld application

1 Understand the basics of the deployment and service

run kubectl get deploy/hw -o yaml. This will return the YAML that composes the helloworld service:

localhost:~ xunyang$ kubectl run hw --image=karthequian/helloworld --port=80
deployment.apps "hw" created
localhost:~ xunyang$ kubectl get deployment/hw -o yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  creationTimestamp: 2018-04-16T04:41:05Z
  generation: 1
  labels:
    run: hw
  name: hw
  namespace: default
  resourceVersion: "11258"
  selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/hw
  uid: 5f8fbd84-4130-11e8-a846-0800272fd392
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      run: hw
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: hw
    spec:
      containers:
      - image: karthequian/helloworld
        imagePullPolicy: Always
        name: hw
        ports:
        - containerPort: 80
          protocol: TCP
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
status:
  availableReplicas: 1
  conditions:
  - lastTransitionTime: 2018-04-16T04:41:05Z
    lastUpdateTime: 2018-04-16T04:41:05Z
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: "True"
    type: Available
  - lastTransitionTime: 2018-04-16T04:41:05Z
    lastUpdateTime: 2018-04-16T04:41:10Z
    message: ReplicaSet "hw-596b578c58" has successfully progressed.
    reason: NewReplicaSetAvailable
    status: "True"
    type: Progressing
  observedGeneration: 1
  readyReplicas: 1
  replicas: 1
  updatedReplicas: 1

The Kubernetes service also comprises YAML.
run kubectl get service hw -o yaml

localhost:~ xunyang$ kubectl expose deployment hw --type=NodePort
service "hw" exposed
localhost:~ xunyang$ kubectl get services
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
hw           NodePort    10.107.135.14   <none>        80:30764/TCP   0s
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP        19h
localhost:~ xunyang$ kubectl get service hw -o yaml
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: 2018-04-16T04:44:21Z
  labels:
    run: hw
  name: hw
  namespace: default
  resourceVersion: "11471"
  selfLink: /api/v1/namespaces/default/services/hw
  uid: d4c8b9c5-4130-11e8-a846-0800272fd392
spec:
  clusterIP: 10.107.135.14
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 30764
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    run: hw
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}

2 Create our deployment using YAML

create helloworld-all.yaml file, content as below

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: helloworld-all-deployment
spec:
  selector:
    matchLabels:
      app: helloworld
  replicas: 1 # tells deployment to run 1 pods matching the template
  template: # create pods using pod definition in this template
    metadata:
      labels:
        app: helloworld
    spec:
      containers:
      - name: helloworld
        image: karthequian/helloworld:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: helloworld-all-service
spec:
  # if your cluster supports it, uncomment the following to automatically create
  # an external load-balanced IP for the frontend service.
  type: LoadBalancer
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: helloworld

3 Execute our deployment using YAML

localhost:~ xunyang$ kubectl create -f helloworld-all.yaml 
deployment.apps "helloworld-all-deployment" created
service "helloworld-all-service" created
localhost:~ xunyang$ kubectl  get all
NAME                                         READY     STATUS    RESTARTS   AGE
helloworld-all-deployment-7c46b4c7dc-2x756   1/1       Running   0          1s

NAME                     TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
helloworld-all-service   LoadBalancer   10.98.124.82   <pending>     80:30100/TCP   1s
kubernetes               ClusterIP      10.96.0.1      <none>        443/TCP        1m

NAME                        DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
helloworld-all-deployment   1         1         1            1           1s

NAME                                   DESIRED   CURRENT   READY     AGE
helloworld-all-deployment-7c46b4c7dc   1         1         1         1s
localhost:~ xunyang$ 

4 Verify that the application is working as expected

localhost:~ xunyang$ kubectl create -f helloworld-all.yaml 
deployment.apps "helloworld-all-deployment" created
service "helloworld-all-service" created
localhost:~ xunyang$ kubectl  get all
NAME                                         READY     STATUS    RESTARTS   AGE
helloworld-all-deployment-7c46b4c7dc-2x756   1/1       Running   0          1s

NAME                     TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
helloworld-all-service   LoadBalancer   10.98.124.82   <pending>     80:30100/TCP   1s
kubernetes               ClusterIP      10.96.0.1      <none>        443/TCP        1m

NAME                        DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
helloworld-all-deployment   1         1         1            1           1s

NAME                                   DESIRED   CURRENT   READY     AGE
helloworld-all-deployment-7c46b4c7dc   1         1         1         1s
localhost:~ xunyang$ minikube service helloworld-all-service
Opening kubernetes service default/helloworld-all-service in default browser...

5 Scale the helloworld application

localhost:~ xunyang$ kubectl get all
NAME                                         READY     STATUS              RESTARTS   AGE
helloworld-all-deployment-7c46b4c7dc-sl9tx   0/1       ContainerCreating   0          0s

NAME                     TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
helloworld-all-service   LoadBalancer   10.110.116.85   <pending>     80:30265/TCP   0s
kubernetes               ClusterIP      10.96.0.1       <none>        443/TCP        2m

NAME                        DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
helloworld-all-deployment   1         1         1            0           0s

NAME                                   DESIRED   CURRENT   READY     AGE
helloworld-all-deployment-7c46b4c7dc   1         1         0         0s
localhost:~ xunyang$ kubectl scale --replicas=3 deploy/helloworld-all-deployment
deployment.extensions "helloworld-all-deployment" scaled
localhost:~ xunyang$ kubectl get all
NAME                                         READY     STATUS              RESTARTS   AGE
helloworld-all-deployment-7c46b4c7dc-bzsgv   0/1       ContainerCreating   0          0s
helloworld-all-deployment-7c46b4c7dc-sl9tx   1/1       Running             0          15s
helloworld-all-deployment-7c46b4c7dc-vd4h7   0/1       ContainerCreating   0          0s

NAME                     TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
helloworld-all-service   LoadBalancer   10.110.116.85   <pending>     80:30265/TCP   15s
kubernetes               ClusterIP      10.96.0.1       <none>        443/TCP        2m

NAME                        DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
helloworld-all-deployment   3         3         3            1           15s

NAME                                   DESIRED   CURRENT   READY     AGE
helloworld-all-deployment-7c46b4c7dc   3         3         1         15s
localhost:~ xunyang$ kubectl get all
NAME                                         READY     STATUS              RESTARTS   AGE
helloworld-all-deployment-7c46b4c7dc-bzsgv   0/1       ContainerCreating   0          3s
helloworld-all-deployment-7c46b4c7dc-sl9tx   1/1       Running             0          20s
helloworld-all-deployment-7c46b4c7dc-vd4h7   1/1       Running             0          3s

NAME                     TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
helloworld-all-service   LoadBalancer   10.110.116.85   <pending>     80:30265/TCP   20s
kubernetes               ClusterIP      10.96.0.1       <none>        443/TCP        2m

NAME                        DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
helloworld-all-deployment   3         3         3            2           20s

NAME                                   DESIRED   CURRENT   READY     AGE
helloworld-all-deployment-7c46b4c7dc   3         3         2         20s
localhost:~ xunyang$ kubectl get all
NAME                                         READY     STATUS    RESTARTS   AGE
helloworld-all-deployment-7c46b4c7dc-bzsgv   1/1       Running   0          8s
helloworld-all-deployment-7c46b4c7dc-sl9tx   1/1       Running   0          25s
helloworld-all-deployment-7c46b4c7dc-vd4h7   1/1       Running   0          8s

NAME                     TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
helloworld-all-service   LoadBalancer   10.110.116.85   <pending>     80:30265/TCP   25s
kubernetes               ClusterIP      10.96.0.1       <none>        443/TCP        2m

NAME                        DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
helloworld-all-deployment   3         3         3            3           25s

NAME                                   DESIRED   CURRENT   READY     AGE
helloworld-all-deployment-7c46b4c7dc   3         3         3         25s

6 clear data

localhost:~ xunyang$ kubectl delete deployment --all
deployment.extensions "helloworld-all-deployment" deleted
localhost:~ xunyang$ kubectl delete services --all
service "helloworld-all-service" deleted
service "kubernetes" deleted
localhost:~ xunyang$ kubectl  get all
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   0s
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,858評(píng)論 0 10
  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,661評(píng)論 5 6
  • 你是內(nèi)向的人嗎?你是情感豐富的人嗎?你會(huì)敏感到風(fēng)若刺骨,光若穿針嗎?如果不是,你沒有隨陽光中漂浮的粒子舞動(dòng)過,...
    民間正道閱讀 416評(píng)論 0 0
  • 作者:樊榮強(qiáng) 這本書最初的構(gòu)思,至今已經(jīng)有三四年了。在我兩年前出版的《20天練成脫稿講話》里面也預(yù)告過,許多讀者不...
    樊榮強(qiáng)閱讀 399評(píng)論 1 3
  • 不能失去夢(mèng)想 不能失去往前行的動(dòng)力 我們應(yīng)該一直不斷得去讀更多的書 看遍中國(guó)的山河 心中 不必裝天下 但是 要裝上...
    胖R只有18歲閱讀 191評(píng)論 0 2

友情鏈接更多精彩內(nèi)容