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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,151评论 0 10
  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 14,595评论 5 6
  • 你是内向的人吗?你是情感丰富的人吗?你会敏感到风若刺骨,光若穿针吗?如果不是,你没有随阳光中漂浮的粒子舞动过,...
    民间正道阅读 2,823评论 0 0
  • 作者:樊荣强 这本书最初的构思,至今已经有三四年了。在我两年前出版的《20天练成脱稿讲话》里面也预告过,许多读者不...
    樊荣强阅读 2,720评论 1 3
  • 不能失去梦想 不能失去往前行的动力 我们应该一直不断得去读更多的书 看遍中国的山河 心中 不必装天下 但是 要装上...
    胖R只有18岁阅读 1,202评论 0 2