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

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

March 14, 2019
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. 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
  8. $ kubectl get deployment symfony-demo -o yaml apiVersion: extensions/v1beta1 kind:

    Deployment metadata: annotations: ... spec: ... template: ... spec: containers: - name: symfony-demo image: symfony-demo:1.1.0
  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. Sees the new Service has the Type LoadBalancer and creates

    An External LB at the Cloud Provider
  12. The ingress controller (nginx) listens on Ingress Resources and configures

    itself to route incoming traffic based on the host header to the correct running pods
  13. apiVersion: v1 kind: PersistentVolumeClaim metadata: name: postgresql-pv-claim labels: name: postgresql

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

    containers: … volumes: - name: postgresql-data persistentVolumeClaim: claimName: postgresql-pv-claim
  15. $ helm install stable/elasticsearch $ helm install stable/fluentd-elasticsearch --set elasticsearch.host=elasticsearch-

    client,elasticsearch.port=9200 $ helm install stable/kibana # with some configuration
  16. Still, if you make a code change you have to

    commit, push, build, deploy
  17. $ telepresence T: Starting proxy with method 'vpn-tcp'... @fhgbvx65xg|bash-3.2$ curl

    http://quote-svc/quote | jq '.' [ { "ID": 503, "title": "stefan sagmeister", "content": "<p>...</p>\n", "link": "https://quotesondesign.com/stefan- sagmeister-2/" } ]
  18. $ telepresence --swap-deployment quote-svc --namespace dev-flow-demo --expose 3000 --run npm

    run debug T: Starting proxy with method 'vpn-tcp',... T: Forwarding remote port 3000 to local port 3000.... > [email protected] debug /Users/bhofmann/forge_test/quote- svc > nodemon --inspect quote-svc.js [nodemon] watching: *.* [nodemon] starting `node --inspect quote-svc.js` Debugger listening on ws://127.0.0.1:9229/83aa27ac- d879-4b50-a228-440354cca791 quote svc listening on port 3000!