Pluralsight Notes – Getting Started with Kubernetes

Getting Started with Kubernetes by Nigel Poulton, begins your journey into understanding Kubernetes and how it has become a crucial platform for container management. The major cloud service providers have jumped on the Kubernetes bandwagon and have their own K8 service offerings, to make your container management even easier. However, I would still recommend getting a base understanding of how it all works before diving into a specific cloud providers implementation. This course will teach you the fundamentals of the Kubernetes architecture and how the platform comes together to make container management a breeze. Once you get through the theoretical, the rest of the course is dedicated to hands on experience. By the end of the course you will have installed and deployed a Kubernetes cluster along with a simple application.

What is Kubernetes?

    • Created by Google
    • Open source
    • Written in Go
    • Managing containers at scale
    • K8s – short hand for kubernetes
    • Data center is a computer – pool of compute network and storage – Application developers do not care where code is run
    • Competitors – Docker Swarm / Mesosphere os
    • Platform Agnostic
    • Cluster manager / orchestrator – give it work to run and it makes the decisions on where to run it

Kubernetes Architecture

      • Orchestrator for microservice apps that run on containers
      • Pods individual container deployments
      • Masters – cluster controller
      • Nodes – group of pods working together – do the work – report back to masters
      • Deployment definition in YAML file – file given to K8s cluster and deploys app in the cluster
      • Master
        • Common setup on a single machine
        • Free of user workloads – No Pods
        • Contains an API – kube-apiserver – consumes json – accepts the YAML deployment file
        • Cluster store – persistent storage – config – uses etcd (Open source key/value store)
        • kube-controller-manager – Node controller/Endpoint Controller/Namespace controller – watches for changes
        • kube-scheduluer – watches apiserver for new pods – assigns work to nodes
      • Nodes (Minions)
        • Kubernetes workers
        • Kubelet – agent – watches for work / instantiates pods / reports back to master / registers node with cluster / endpoint 10255
          • /spec
          • /healthz
          • /pods
        • Container engine – pulling images / starting & stopping containers
        • kube-proxy – network brain / 1 IP per pod / light weight load balancing within in a node
      • Operates on declarative model – YAML or JSON – describe desired state
        • Manifest files – records of intent – desired state of the cluster
        • Continues to keep actual state in sync with desired state – reconciliation loops
      • Pods
        • Atomic unit of deployment
        • Containers run in pods / multiple containers can run in a pod
        • Sandbox to run containers
        • Multiple containers in a pod would share the pod environment (tight coupling)
        • Unit of scaling is done by adding pods not by adding containers in a pod
      • Services
        • IP Churn when pods die and are recreated
        • Created with YAML manifest – point front end pods to service – load balances requests to back end pods
        • KubernetesServices
          Kubernetes Services Diagram
        • Stable abstraction point for pod communication
        • Labels tie the service and backend pods together – load balance over
        • Helpful for rolling updates and keeping multiple versions around until deployments have settled
        • Only send traffic to healthy pods
        • Can point to things outside the cluster
        • Can be configured for session affinity
        • Uses TCP by default
        • Random load balancing by default
      • Deployments
        • Declarative
        • Self documenting
        • Versioned
        • Spec once / deploy many
        • Simple rolling updates and rollbacks
        • REST Objects
        • Deployed vie YAML or JSON manifests
        • Deployed Via the apiserver
        • Add features to replica sets
        • Multiple concurrent versions – blue green deployments / canary releases

Installing Kubernetes

    • Minikube – local dev environment
      • Creates local vm and spins up a single node cluster
      • localkube binary – runs the master and node
      • container runtime – docker default or rocket
      • $kubectl – kube client
      • minikube dashboard – opens dashboard in browser
    • Google Kontainer Engine
      • K stands for Kubernetes
      • Layered on top of google compute engine
      • Google cloud platform
      • Kubernetes as a service
    • AWS with kops (Kubernetes operations)
      • kops handles AWS infrastructure for kubernetes
      • No kops binary for windows/mac
      • Need kubectl, kops binary, AWS CLI
      • Need IAM Account Creds in AWS
      • Need properly configured DNS
        • Subdomain delegated to AWS Route53
    • Manual Install
      • kubeadm
      • Every (Master/Node) needs – Docker / Kubelet / Kubeadm / Kubectl / CNI
      • kubectl apply – weave-kube-1.6 (weavenet) – pod networking

Working with Pods

    • Smallest atomic unit of scheduling
    • Pod containers 1 or more containers
    • Pod gets single IP (network namespace)
      • Each container would need to be on a different port
    • Inter-pod communication is done on the Pod network – each pod can talk to each other by IP
    • Intra-pod communication is done through the localhost
    • Atomic deployments – pod cannot be “partially” up
    • Lifecycle
      • Manifest file
      • Send to api server to get scheduled
      • Pending state
      • Running
      • Succeeded
    • When a pod dies they are replaced – new one with same config can take place
    • Manifest contains the KIND of resource to deploy
    • kubectl get pods – gets pods in default namespace
    • Replication controller implements desired state
    • Do not interact directly with pods – use higher level resource – replication controller

Kubernetes Services

    • REST Object defined in a YAML file
    • Service creates reliable – IP /DNS / Port
    • Requests are load balanced across the pods
    • Service contains an updated list of Pod IPs
    • Service uses a label selector which allows the flexible load balancing
    • ServiceType
      • ClusterIP – Stable internal cluster ip
      • NodePort – Exposes the app outside of the cluster by adding a cluster-wide port on top of clusterip
      • LoadBalancer – Integrates NodePort with cloud-based load balancers

Kubernetes Deployments

    • Rolling updates – seamless rollbacks
    • Deployments manage replica sets and replica sets manage pods
    • YAML deployment file given to api server
      • Creates replica set with pods
      • Push an update – make changes to same YAML deployment file
        • Rolling update – This will create a new replica set with the new changes bringing up 1 pod at a time and pulling down 1 pod at a time from the old version (Configurable)
        • Replica set is still there – only pods are removed and the replica set is spun down – roll back would just put the original pods back
        • Should put deployment YAML file in version control
    • minReadySeconds – determine how many seconds before marking ready and moving to the next
    • strategy – define rolling update procedure
    • –record flag – audit history of deployment versions