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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,590评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 86,808评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,151评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,779评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,773评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,656评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,022评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,678评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 41,038评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,659评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,756评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,411评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,005评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,973评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,053评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,495评论 2 343

推荐阅读更多精彩内容

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