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

Getting started with Kubernetes

Getting started with Kubernetes

Getting started with 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, and show you, based on a practical example, how to continuously deploy a web application into it.

Bastian Hofmann

June 19, 2018
Tweet

More Decks by Bastian Hofmann

Other Decks in Programming

Transcript

  1. AWS

  2. • A docker image built from a Dockerfile that contains

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

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

    port space • Separate FS and process spaces • Ports are not accessible from outside of the pod Pod
  5. • Volumes can be mounted into a container to access

    a ConfigMap, Secret or a folder on the host Volumes
  6. 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
  7. 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
  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 https://php-app.k8s.foo.com:443/ PHP Application POD PHP Application POD
  9. 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
  10. $ 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",
  11. PHP

  12. 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:
  13. 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: /
  14. 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 • …
  15. kind: Service apiVersion: v1 metadata: name: symfony-demo spec: ports: -

    name: http port: 80 targetPort: 80 protocol: TCP selector: app: symfony-demo
  16. 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
  17. 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
  18. 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: {}
  19. apiVersion: v1 kind: PersistentVolumeClaim metadata: name: postgresql-pv-claim labels: name: postgresql

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

    containers: … volumes: - name: postgresql-data persistentVolumeClaim: claimName: postgresql-pv-claim
  21. 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
  22. spec: containers: - name: test-container image: k8s.gcr.io/busybox command: [ "/bin/sh",

    "-c", "env" ] envFrom: - configMapRef: name: special-config
  23. 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
  24. ...