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

Deploying your first Micro-Service application to Kubernetes

Deploying your first Micro-Service application 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 workshop you will deploy your first application which consists of multiple Micro-Services to Kubernetes and learn how you can use Persistant Storage and set upsensible Monitoring and Logging tooling.

Bastian Hofmann

June 24, 2019
Tweet

More Decks by Bastian Hofmann

Other Decks in Programming

Transcript

  1. @BastianHofmann
    Deploying your first
    Micro-Service application
    to Kubernetes
    Bastian Hofmann

    View Slide

  2. View Slide

  3. Container orchestration platform

    View Slide

  4. Deploy, run and scale your services
    in isolated containers

    View Slide

  5. Very Powerful

    View Slide

  6. Lot’s of large company backers

    View Slide

  7. No vendor lock in

    View Slide

  8. Standardized APIs

    View Slide

  9. Runs on

    View Slide

  10. Your laptop

    View Slide

  11. View Slide

  12. Bare metal

    View Slide

  13. Cloud Providers

    View Slide

  14. And if you don't want to install and
    maintain Kubernetes yourself

    View Slide

  15. Managed Kubernetes

    View Slide

  16. View Slide

  17. Easy setup

    View Slide

  18. Easy upgrades

    View Slide

  19. Easy scaling

    View Slide

  20. Features

    View Slide

  21. Load Balancing

    View Slide

  22. Distributed Persistent Storage

    View Slide

  23. Backups

    View Slide

  24. But this workshop is about
    how to use Kubernetes

    View Slide

  25. Learning curve

    View Slide

  26. Agenda

    View Slide

  27. View Slide

  28. • Deployments
    • CronJobs
    • Readiness and Liveness-Probes, NodeSelectors & PodAffinities
    • ConfigMaps & Secrets
    • External DNS, Let'sEncrypt with cert-manager, nginx-ingress-
    controller
    • Running a MySQL DB
    • Helm
    • Service Discovery

    View Slide

  29. Optionally

    View Slide

  30. • Service Meshes with LinkerD
    • Monitoring with Prometheus, Grafana and Alertmanager
    • Logging with ElasticSearch, FluentD and Kibana
    • GitOps with Flux
    • Development with Tilt and Telepresence

    View Slide

  31. But first

    View Slide

  32. Why containers?

    View Slide

  33. Services run in isolation

    View Slide

  34. Everything needed to run a service in
    one image

    View Slide

  35. Make things …

    View Slide

  36. Easier to deploy

    View Slide

  37. Easier to upgrade system
    dependencies

    View Slide

  38. Easier to develop

    View Slide

  39. Easier to scale

    View Slide

  40. Better resource usage

    View Slide

  41. #safeThePlanet

    View Slide

  42. View Slide

  43. 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”]

    View Slide

  44. docker build -t gitlab.syseleven.de/syseleven/symfony-
    demo:2.0.0 .

    View Slide

  45. docker run -p 8080:80 syseleven/symfony-demo:2.0.0
    docker push syseleven/symfony-demo:2.0.0

    View Slide

  46. Kubernetes helps you to run and
    deploy containers

    View Slide

  47. Let’s define some core concepts and
    terminology first

    View Slide

  48. Kubernetes Cluster

    View Slide

  49. • A docker image built from
    a Dockerfile that contains
    everything a service needs
    to run
    Image

    View Slide

  50. • A container runs a docker
    image.
    • Only 1 process can run
    inside of a container
    Container

    View Slide

  51. • A group of 1 or more
    containers
    • Same port space
    • Within a Pod:
    communication over
    localhost
    • Every Pod has it's own IP
    • All Pods can talk with each
    other
    • IPs change all the time
    Pod

    View Slide

  52. • Defines and manages how
    many instances of a pod
    should run
    • ReplicaSet is tied to a
    specific definition of a Pod
    which is tied to specific
    image versions of the
    container
    • Image versions in
    ReplicaSets can't be
    updated
    Replica Set

    View Slide

  53. • Manages updates and
    rollbacks of replica sets
    Deployment

    View Slide

  54. • Internal LoadBalancer
    • Makes all pods matching a
    set of labels accessible
    through a stable, internal
    IP address
    • You can attach external IP
    address through an cloud
    LoadBalancer
    Service

    View Slide

  55. • Makes a service
    accessible to the outside
    of Kubernetes through an
    ingress controller (e.g.
    nginx)
    • Traffic is routed by routing
    rules, usually Host header
    Ingress

    View Slide

  56. • A physical server
    • Containers get distributed
    automatically
    Node

    View Slide

  57. • Key/Value storage for
    configuration
    ConfigMap

    View Slide

  58. • Key/Value storage for
    configuration, usually
    passwords.
    Secret

    View Slide

  59. • Volumes can be mounted
    into a container to access
    a ConfigMap, Secret,
    persistent volumes with
    network storage or a folder
    on the node
    Volumes

    View Slide

  60. • Dedicated environment to
    deploy services in
    Namespaces

    View Slide

  61. • Includes a Pod that is
    started in a regular interval
    • Process in the container
    should finish at some point
    CronJob

    View Slide

  62. • Defines Pod that should
    run once on every Node
    • Useful for monitoring or
    logging daemons
    DaemonSet

    View Slide

  63. • Ensures that Pods are
    started and run in a
    specific order
    • Each Pod of a StatefulSet
    can have its own persistent
    volume
    • Pod names stay the same
    StatefulSet
    1 2

    View Slide

  64. ...

    View Slide

  65. Everything is a resource

    View Slide

  66. You interact with Kubernetes by
    creating, receiving, updating and
    deleting resources

    View Slide

  67. Kubernetes has controllers to listen
    on these interactions and get the
    cluster in the desired state

    View Slide

  68. The Kubernetes API can be extended
    with additional Resources and
    Controllers

    View Slide

  69. CustomResourceDefinitions

    View Slide

  70. Certificate, Backup, Restore,
    MySQLCluster, Function, ...

    View Slide

  71. Controllers / Operators

    View Slide

  72. 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

    View Slide

  73. $ kubectl apply -f deployment.yaml

    View Slide

  74. $ kubectl get deployments
    NAME DESIRED CURRENT UP-TO-DATE AVAILABLE
    AGE
    symfony-demo 1 1 1 1
    21h

    View Slide

  75. $ 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

    View Slide

  76. $ kubectl delete deployment symfony-demo

    View Slide

  77. Tooling

    View Slide

  78. kubectl

    View Slide

  79. REST API

    View Slide

  80. $ 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",

    View Slide

  81. kubernetes-dashboard

    View Slide

  82. View Slide

  83. Helm
    The package manager for
    Kubernetes

    View Slide

  84. $ helm install stable/wordpress

    View Slide

  85. Demo

    View Slide

  86. Demo code and instructions:
    https:/
    /github.com/bashofmann/kubernetes-workshop-halfday
    http:/
    /bit.ly/2RwgrV8 => Download and copy to ~/.kube/config
    Install kubectl:
    https:/
    /kubernetes.io/docs/tasks/tools/install-kubectl/
    If you are not allowed to install kubectl locally:
    http:/
    /bit.ly/2WZih1Z

    View Slide

  87. # 01 Deploying a simple Web
    Application

    View Slide

  88. What did just happen?

    View Slide

  89. View Slide

  90. Deployment created

    View Slide

  91. Sees new Deployment
    And creates new
    ReplicaSet with 1 desired
    replica

    View Slide

  92. Sees new ReplicaSet and
    Creates Pod for ReplicaSet

    View Slide

  93. Sees new unscheduled Pod and
    Schedules it to Node

    View Slide

  94. Sees it is supposed to start a Pod
    And starts its Containers

    View Slide

  95. Service created

    View Slide

  96. Sees the new Service
    And configures
    IP Table Rules and DNS entries

    View Slide

  97. Sees the new Service has the
    Type LoadBalancer and creates
    An External LB at the Cloud Provider

    View Slide

  98. How is traffic routed to the Pod

    View Slide

  99. The Service loadbalances incoming
    traffic to all available Pods

    View Slide

  100. Every Service has a virtual IP

    View Slide

  101. Round Robin with IP Tables rules

    View Slide

  102. OpenStack LoadBalancer

    View Slide

  103. # 10 Using an Ingress with TLS

    View Slide

  104. 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

    View Slide

  105. Cert-manager listens on Ingresses
    and if they want TLS, requests a
    certificate from LetsEncrypt

    View Slide

  106. External-DNS listens on Ingresses
    and creates DNS entries at
    DigitalOcean

    View Slide

  107. How is traffic routed to the Pod

    View Slide

  108. OpenStack LoadBalancer

    View Slide

  109. Operators

    View Slide

  110. View Slide

  111. # 15 Service Meshes

    View Slide

  112. What are Service Meshes?

    View Slide

  113. View Slide

  114. They provide

    View Slide

  115. Metrics and Traces

    View Slide

  116. Transparent End-To-End Encryption

    View Slide

  117. Advanced Routing

    View Slide

  118. Istio

    View Slide

  119. LinkerD

    View Slide

  120. $ linkerd install | kubectl apply -f -

    View Slide

  121. Flux

    View Slide

  122. View Slide