Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Kubernetes

Introduction to Kubernetes

Kubernetes is a very powerful container orchestration platform that is quickly gaining traction and gives you lots of benefits in deploying, running and scaling your microservice web application. But it has also a steep learning curve. In this talk I will introduce you to Kubernetes, why you would want to use it and all the tooling around Kubernetes with the help of practical examples.

Bastian Hofmann

May 11, 2018
Tweet

More Decks by Bastian Hofmann

Other Decks in Programming

Transcript

  1. AWS

  2. FROM php:7.2-apache WORKDIR /var/www/html RUN apt-get update -y && \

    apt-get install -y --no-install-recommends curl \ rm -rf /var/lib/apt/lists/* ENV TMP_DIR /tmp COPY . /var/www/html/ EXPOSE 80 ENTRYPOINT [“apache2”, “-DFOREGROUND”]
  3. • A docker image built from a Dockerfile that contains

    everything a service needs to run Image
  4. • A container runs a docker image. • Only 1

    process can run inside of a container Container
  5. • A group of 1 or more containers • Same

    port space • Ports are not accessible from outside of the pod Pod
  6. • Volumes can be mounted into a container to access

    a ConfigMap, Secret or a folder on the host Volumes
  7. PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER PHP Application

    POD ReplicaSet: 2 instances PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER PHP Application POD
  8. PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER ReplicaSet: 2

    instances PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER CONFIG WEB :80 PHP Application POD PHP Application POD
  9. PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER ReplicaSet: 2

    instances PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER CONFIG WEB :80 https://php-app.k8s.foo.com:443/ PHP Application POD PHP Application POD
  10. NAME READY STATUS RESTARTS AGE kubernetes-dashboard-5b5bf59977-t9xb9 1/1 Running 2 9d

    nginx-ingress-controller-5549f5597c-97kcw 0/1 Running 2 9d nginx-ingress-default-backend-564d9d9477-tmnnr 1/1 Running 4 9d mysql-556c9b5bcb-5jdrt 1/1 Running 1 8d symfony-demo-5b75f5fc6-c7wr9 1/1 Running 0 8d symfony-demo-5b75f5fc6-jg8n4 1/1 Running 23 8d
  11. $ kubectl proxy --port=8080 $ curl http://localhost:8080/api/v1/namespaces/default/ pods { "kind":

    "PodList", "apiVersion": "v1", "metadata": { "selfLink": "/api/v1/namespaces/default/pods", "resourceVersion": "336834" }, "items": [ { "metadata": { "name": "kubernetes-dashboard-5b5bf59977-t9xb9",
  12. PHP

  13. kind: Deployment apiVersion: extensions/v1beta1 metadata: name: symfony-demo spec: template: metadata:

    labels: app: symfony-demo spec: containers: - name: symfony-demo image: symfony-demo:1.0.0 ports:
  14. containers: - name: symfony-demo image: symfony-demo:1.0.0 ports: - containerPort: 80

    livenessProbe: httpGet: path: / port: 80 timeoutSeconds: 1 initialDelaySeconds: 10 readinessProbe: httpGet: path: /
  15. Many more options • Setting environment variables • Mounting volumes

    • Requesting resources • Defining upgrade strategies • Defining command • Configure networking • Configure the scheduler • Listen on lifecycle events • Configure system capabilities for the container • …
  16. kind: Service apiVersion: v1 metadata: name: symfony-demo spec: ports: -

    name: http port: 80 targetPort: 80 protocol: TCP selector: app: symfony-demo
  17. kind: Ingress apiVersion: extensions/v1beta1 metadata: name: symfony-demo spec: rules: -

    host: symfony-demo.local.k8s http: paths: - path: / backend: serviceName: symfony-demo servicePort: 80
  18. kind: Deployment apiVersion: extensions/v1beta1 metadata: name: symfony-demo spec: template: spec:

    containers: - name: symfony-demo image: symfony-demo:1.1.0 ports: - containerPort: 80
  19. apiVersion: batch/v1beta1 kind: CronJob metadata: name: cron-job spec: schedule: "*/1

    * * * *" jobTemplate: spec: template: spec: containers: - name: cron-job image: your-cron-job restartPolicy: OnFailure
  20. kind: Service apiVersion: v1 metadata: name: symfony-demo spec: ports: -

    name: http port: 80 targetPort: 80 protocol: TCP selector: app: symfony-demo
  21. $ kubectl get service symfony-demo NAME TYPE CLUSTER-IP PORT(S) AGE

    symfony-demo ClusterIP 10.106.119.24 80/TCP 6d
  22. DNS

  23. PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER PHP Application

    POD NodeJS LINKERD NodeJS Service POD NodeJS LINKERD NodeJS Service POD
  24. PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER PHP Application

    POD NodeJS LINKERD NodeJS Service POD NodeJS LINKERD NodeJS Service POD
  25. PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER PHP Application

    POD NodeJS LINKERD NodeJS Service POD NodeJS LINKERD NodeJS Service POD
  26. PHP-FPM NGINX LINKERD STATSD MEM CACHED MONGO ROUTER PHP Application

    POD NodeJS LINKERD NodeJS Service POD NodeJS LINKERD NodeJS Service POD
  27. apiVersion: v1 kind: Pod metadata: name: test-pd spec: containers: -

    image: k8s.gcr.io/test-webserver name: test-container volumeMounts: - mountPath: /cache name: cache-volume volumes: - name: cache-volume emptyDir: {}
  28. apiVersion: v1 kind: PersistentVolumeClaim metadata: name: postgresql-pv-claim labels: name: postgresql

    spec: storageClassName: generic accessModes: - ReadWriteOnce resources: requests: storage: 10Gi
  29. apiVersion: extensions/v1beta1 kind: Deployment metadata: name: postgresql spec: template: spec:

    containers: … volumes: - name: postgresql-data persistentVolumeClaim: claimName: postgresql-pv-claim
  30. spec: containers: - name: test-container image: k8s.gcr.io/busybox command: [ "/bin/sh",

    "-c", "env" ] env: - name: SPECIAL_KEY valueFrom: configMapKeyRef: name: special-config key: special-key
  31. spec: containers: - name: test-container image: k8s.gcr.io/busybox command: [ "/bin/sh",

    "-c", "env" ] envFrom: - configMapRef: name: special-config
  32. spec: containers: - name: test-container image: k8s.gcr.io/busybox command: [ "/bin/sh",

    "-c", "ls /etc/config/" ] volumeMounts: - name: config-volume mountPath: /etc/config volumes: - name: config-volume configMap: name: special-config