IE retrospectiveResearch • Kube Small Overview

Kube Deploy Service Ingress

kube-specs-flow

This blog diagram shows three resource definitions that are also found in the social-dev.yaml: Deployment, Service and Ingress

Deployment defines how our application (node.js) is exposed to kube services, which ports it uses, env vars it has etc.

Service maps the port from a Deployment to a name and port inside kube's nameservice. social-dev.yaml, for example, makes a Deployment available at https://social-dev-service:433

kind: Service
apiVersion: v1
metadata:
  name: social-dev-service
  selector:
    app: social-dev
  ports:
    - name: server
      port: 443  # Server listens on HTTP2 secure, so that is 443
      targetPort: 8000

Anywhere inside kube, application responses are served at https://social-dev-service:433,

$ kubectl get pods | grep beta-dev
cms2-beta-dev-9f5f99ccf-cq99r                 1/1     Running       0          2d16h
$ kubectl exec --stdin --tty cms2-beta-dev-9f5f99ccf-cq99r -- /bin/sh 
pod$ wget -qO- --no-check-certificate https://social-dev-service:443/health/alive
{"status":"pass","version":"2.39.0","serviceID":"social-dev-deployment","description":"Service for all Deutsche Telekom integrations.","details":{"started":[{"status":"pass","time":"2020-10-16T21:42:06.245Z"}],"shutdown":[{"status":"pass","time":"2020-10-16T21:42:06.245Z"}]}}

Ingress maps the kube service to an external host and path

kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: social-dev-service
  rules:
    - host: kube.venom360.com
      http:
        paths:
          - path: /social-dev(/|$)(.*)
            backend:
              serviceName: social-dev-service
              servicePort: 443

Apply the yaml to kube as many times as you wish with this "apply" command. Any yaml filename is good and if we wanted to use separated ingress.yaml, deployment.yaml and service.yaml that would work as well

$ # apply all specs inside the yaml file
$ kubectl apply -f deploy/social-dev.yaml

After the yaml is applied, deployment pods are added and removed using the scale command. For example, remove all pods then use two pods.

$ # list pods
$ kubectl get pods -l app=social-dev
NAME                                     READY   STATUS    RESTARTS   AGE
social-dev-deployment-7f6cdcd9dd-bvwhd   1/1     Running   0          20h
$ # scale to 0
$ kubectl scale deployment social-dev-deployment --replicas=0
deployment.apps/social-dev-deployment scaled
$ # list pods again
$ kubectl get pods -l app=social-dev
No resources found in default namespace.
$ # scale to 2
$ kubectl scale deployment social-dev-deployment --replicas=2
deployment.apps/social-dev-deployment scaled
$ kubectl get pods -l app=social-dev
NAME                                     READY   STATUS    RESTARTS   AGE
social-dev-deployment-7f6cdcd9dd-8zsg9   0/1     Running   0          22s
social-dev-deployment-7f6cdcd9dd-zqk9k   0/1     Running   0          22s
$ # scale to 1
$ kubectl scale deployment social-dev-deployment --replicas=1
deployment.apps/social-dev-deployment scaled

Kube services will expose pods automatically after they're started and pass health check