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

Intro to Kubernetes

Intro to Kubernetes

talk for Tokyo Engineering Meeting on 2021-04-22

TAKAHASHI Shuuji

April 22, 2021
Tweet

More Decks by TAKAHASHI Shuuji

Other Decks in Technology

Transcript

  1. Intro to Kubernetes
    2021-04-22 Shuuji Takahashi

    View Slide

  2. Today’s Goals
    ● Understand the overview of Kubernetes
    ● Know basic Kubernetes objects: Node, Pod, Deploy, Service
    ● Three simple Hands-on:
    ○ 1) create kubernetes cluster, 2) create Pod, 3) Deployment
    4) publish Deployment using Service
    ● misc.

    View Slide

  3. What is Kubernetes
    What is Kubernetes? | Kubernetes - https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/

    View Slide

  4. What is Kubernetes
    ● Container orchestration system created by Google and released on 2014
    ○ Google uses Borg (Kubernetes ancestor) internally since 2003
    ○ Google deploys billions of containers every week
    ● Kubernetes run containerized applications in the cluster
    ● Features:
    ○ Automated rollouts and rollbacks
    ○ Self-healing
    ○ Horizontal scaling
    ○ etc.
    Kubernetes - https://kubernetes.io/

    View Slide

  5. Kubernetes
    architecture

    View Slide

  6. Basic Kubernetes objects
    ● Node: represents single master/worker nodes
    ● Pod: a minimum manage unit in the Kubernetes cluster
    ● Deployment: manages one or more Pods across the Kubernetes cluster
    ● Service: expose/publish the Deployment

    View Slide

  7. Node
    ● Node represents single master/worker nodes
    ● 4 Nodes in the diagram
    ○ 1 control-plane Node
    ○ 3 worker Nodes
    ● Node hold information about each node
    ○ CPU, memory, GPU, etc.

    View Slide

  8. Play with Kubernetes
    ● Play with Kubernetes
    https://labs.play-with-k8s.com/
    ● You can create a temporary Kubernetes
    cluster for learning
    ● Expires at 4 hours later
    ● Similar service:
    ○ Kubernetes Playground | Katacoda
    https://www.katacoda.com/courses/kub
    ernetes/playground

    View Slide

  9. Hands-on 1: Create Kubernetes cluster
    Let’s create a Kubernetes cluster
    1. Setup control-plane node
    [node1 ~]$ kubeadm init --apiserver-advertise-address $(hostname -i)
    --pod-network-cidr 10.5.0.0/16Take a note
    2. Take a note of `kubeadm join` command (don’t copy below; token will be
    changed every time):
    [node1 ~]$ kubeadm join 192.168.0.8:6443 --token 800kr4.o240gue4k0k72zcj \
    --discovery-token-ca-cert-hash
    sha256:6caacab32dc51e28fcd006231d547c5e2e3f39ed96626a80d39801345d196311

    View Slide

  10. Hands-on 1: Create Kubernetes cluster
    3. Initialize cluster networking (for “Play with Kubernetes”)
    [node1 ~]$ kubectl apply -f
    https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/kub
    eadm-kuberouter.yaml
    4. Add worker nodes
    [node2 ~]$ kubeadm join 192.168.0.8:6443 --token 800kr4.o240gue4k0k72zcj \
    --discovery-token-ca-cert-hash
    sha256:6caacab32dc51e28fcd006231d547c5e2e3f39ed96626a80d39801345d196311

    View Slide

  11. Hands-on 1: Create Kubernetes cluster
    5. Check Nodes status
    # Get a node list
    [node1 ~]$ kubectl get node
    NAME STATUS ROLES AGE VERSION
    node1 Ready control-plane,master 22m v1.20.1
    node2 Ready 21m v1.20.1
    # Show the detail information
    [node1 ~]$ kubectl describe node/node1
    ...

    View Slide

  12. Pod
    ● Pod is a minimum manage unit in the Kubernetes cluster
    ● Contains one (or more) container inside a Pod
    ● Run application process in the container
    ● For example:
    ○ Nginx container
    ○ PostgreSQL container
    ○ Containerized API server application
    ○ etc.
    Nginx container

    View Slide

  13. Hands-on 2: Create Pod
    ● Create a Pod template YAML file for webserver Pod running nginx container
    [node1 ~]$ kubectl run webserver --image=nginx --dry-run=client -o=yaml > webserver-pod.yaml
    [node1 ~]$ cat webserver-pod.yaml
    apiVersion: v1
    kind: Pod
    metadata:
    creationTimestamp: null
    labels:
    run: webserver
    name: webserver
    spec:
    containers:
    - image: nginx
    name: webserver
    resources: {}
    dnsPolicy: ClusterFirst
    restartPolicy: Always
    status: {}

    View Slide

  14. Hands-on 2: Create Pod
    # Create a Pod
    [node1 ~]$ k apply -f nginx-pod.yaml
    pod/nginx created
    # Check the Pod
    [node1 ~]$ kubectl get pod
    NAME READY STATUS RESTARTS AGE
    nginx 1/1 Running 0 37m
    # Where is the Pod
    [node1 ~]$ kubectl get pod -o wide
    NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
    READINESS GATES
    nginx 1/1 Running 0 34m 10.5.1.4 node2

    View Slide

  15. Deployment
    ● Deployment manages one or more Pods across
    the Kubernetes cluster
    ● Can keep the number of replicas (auto-recovery)
    ● Rolling update
    Nginx
    Nginx
    Nginx

    View Slide

  16. ● Deployment creates and updates Pods across the Kubernetes cluster
    (via ReplicaSet object)
    ● Can keep the number of replicas (auto-recovery)
    ● Realize rolling update
    Deployment
    Nginx
    Nginx
    Nginx

    View Slide

  17. Hands-on 3: Create Deployment
    ● Create a Deployment template YAML file for
    web Deployment running nginx container
    [node1 ~]$ kubectl create deployment web
    --image=nginx:latest --dry-run=client
    -o=yaml > web-deploy.yaml
    [node1 ~]$ cat web-deploy.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    creationTimestamp: null
    labels:
    app: webserver
    name: webserver
    (cont’d)
    spec:
    replicas: 1
    selector:
    matchLabels:
    app: webserver
    strategy: {}
    template:
    metadata:
    creationTimestamp: null
    labels:
    app: webserver
    spec:
    containers:
    - image: nginx:latest
    name: nginx
    resources: {}
    status: {}

    View Slide

  18. Hands-on 3: Create Deployment
    # Create a Deployment
    [node1 ~]$ k apply -f web-deploy.yaml
    deployment.apps/web created
    # Check the Deployment and Pod created
    [node1 ~]$ k get deploy,pod -o wide
    NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES
    SELECTOR
    deployment.apps/web 1/1 1 1 96s nginx nginx:latest
    app=web
    NAME READY STATUS RESTARTS AGE IP NODE
    NOMINATED NODE READINESS GATES
    pod/web-86cd4d65b9-fjbgr 1/1 Running 0 96s 10.5.1.6 node2

    View Slide

  19. Hands-on 3: Create Deployment
    # Access webserver
    [node1 ~]$ curl 10.5.1.6 --head
    HTTP/1.1 200 OK
    Server: nginx/1.19.10
    Date: Wed, 21 Apr 2021 16:24:56 GMT
    Content-Type: text/html
    Content-Length: 612
    Last-Modified: Tue, 13 Apr 2021 15:13:59 GMT
    Connection: keep-alive
    ETag: "6075b537-264"
    Accept-Ranges: bytes

    View Slide

  20. Hands-on 3: Create Deployment
    # Scale up and version down experiments
    [node1 ~]$ vi web-deploy.yaml
    [node1 ~]$ kubectl diff -f web-deploy.yaml
    diff -u -N
    /tmp/LIVE-407848292/apps.v1.Deployment.default.web
    /tmp/MERGED-110938483/apps.v1.Deployment.default.w
    eb
    ---
    /tmp/LIVE-407848292/apps.v1.Deployment.default.web
    2021-04-21 16:27:07.372300600 +0000
    +++
    /tmp/MERGED-110938483/apps.v1.Deployment.default.w
    eb 2021-04-21 16:27:07.384300629+0000
    @@ -6,7 +6,7 @@
    (...)
    creationTimestamp: "2021-04-21T16:22:35Z"
    - generation: 1
    + generation: 2
    Labels:
    app: web
    managedFields:
    @@ -93,7 +93,7 @@
    uid: ac702c97-db70-4322-9af5-589327b084c6
    spec:
    progressDeadlineSeconds: 600
    - replicas: 1
    + replicas: 5
    revisionHistoryLimit: 10
    @@ -110,7 +110,7 @@
    spec:
    containers:
    - - image: nginx:latest
    + - image: nginx:1.18
    imagePullPolicy: Always
    name: nginx

    View Slide

  21. Hands-on 3: Create Deployment
    # apply and watch
    [node1 ~]$ kubectl apply -f web-deploy.yaml; watch kubectl get deploy,pod -o wide
    NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
    deployment.apps/web 5/5 5 5 24m nginx nginx:1.18 app=web
    NAME READY STATUS RESTARTS AGE IP NODE NOMINATED
    NODE READINESS GATES
    pod/web-7989784f96-7dhts 1/1 Running 0 15m 10.5.1.11 node2

    pod/web-7989784f96-g4s2c 1/1 Running 0 12s 10.5.1.51 node2

    pod/web-7989784f96-mct2n 1/1 Running 0 15m 10.5.1.10 node2

    pod/web-7989784f96-mpm2t 1/1 Running 0 15m 10.5.1.9 node2

    pod/web-7989784f96-p87rx 1/1 Running 0 15m 10.5.1.16 node2

    View Slide

  22. Hands-on 3: Create Deployment
    # Access webserver
    [node1 ~]$ curl 10.5.1.1 --head
    HTTP/1.1 200 OK
    Server: nginx/1.18.0
    Date: Wed, 21 Apr 2021 16:48:18 GMT
    Content-Type: text/html
    Content-Length: 612
    Last-Modified: Tue, 21 Apr 2020 14:09:01 GMT
    Connection: keep-alive
    ETag: "5e9efe7d-264"
    Accept-Ranges: bytes

    View Slide

  23. Hands-on 3: Create Deployment
    # Delete Pod intentionally
    [node1 ~]$ kubectl delete pod/
    ...

    View Slide

  24. Service
    ● Service exposes / publishes the Deployment inside the cluster

    View Slide

  25. Other Kubernetes objects
    ● ConfigMap / Secret
    ● StatefulSet
    ● Persistent Volume / Persistent Volume Claim
    ● Service
    ● Ingress
    ● →Next time...?

    View Slide

  26. Kubernetes
    website
    ● Many information
    ○ Concepts, Tasks,
    Tutorials,
    References
    ● Website: https://k8s.io
    ● Maintained by
    Kubernetes community
    & developers at
    #sig-docs
    ● Japanese translation at
    #sig-docs-ja
    Kubernetes Website - https://kubernetes.io/ja/

    View Slide

  27. GKE: Google
    Kubernetes Engine
    ● Full-managed
    Kubernetes cluster
    provided by Google
    Cloud
    ○ Control-plane is
    fully managed
    ● GKE Autopilot mode
    is introduced on
    February 2021
    ○ Worker nodes
    are also fully
    managed
    Building the future with Google Kubernetes Engine | Google Cloud Blog
    https://cloud.google.com/blog/products/containers-kubernetes/building-t
    he-future-with-google-kubernetes-engine

    View Slide

  28. References
    ● Kubernetes Website - https://kubernetes.io/
    ● Play with Kubernetes - https://labs.play-with-k8s.com/
    ● Building the future with Google Kubernetes Engine | Google Cloud Blog -
    https://cloud.google.com/blog/products/containers-kubernetes/building-t
    he-future-with-google-kubernetes-engine
    ● Icon deck: icono-k8s-0.3 - Google Slides -
    https://docs.google.com/presentation/d/15h_MHjR2fzXIiGZniUdHok_FP0
    7u1L8MAX5cN1r0j4U/edit#slide=id.g4cac41f932_1_94

    View Slide

  29. Deploy WordPress & MySQL with Persistent
    Volume ?
    Example: Deploying WordPress and MySQL with Persistent Volumes |
    Kubernetes -
    https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-per
    sistent-volume/

    View Slide