Kubernetes workbook

Kubernetes workbook

  • What is a container
    • container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings. ​
    • ​Available for both Linux and Windows based apps, containerized software will always run the same, regardless of the environment. ​
    • Containers isolate software from its surroundings, for example differences between development and staging environments and help reduce conflicts between teams running different software on the same infrastructure.​
  • What is docker?
    • Docker is the world’s leading software container platform. Ie there are other solutions for managing Containers, Docker just happens to be the most popular.  ​
    • ​It’s an open platform for developing, shipping and running applications.  Developers use Docker to eliminate “works on my machine” problems when collaborating on code with co-workers. ​
    • ​Operators use Docker to run and manage apps side-by-side in isolated containers to get better compute density. ​
    • ​Enterprises use Docker to build agile software delivery pipelines to ship new features faster, more securely and with confidence for both Linux and Windows Server apps. ​
    • Docker Architecture
      • Docker Client​
      • Run commands ​
      • Docker Daemon​
      • images​
      • containers​
      • networks​
      • volumes​
      • Docker Registry​
      • Stores images
  • What is Kubernetes?
    • Kubernetes is an open source system for automating deployment, scaling, and management of containerized applications,” according to the Cloud Native Computing Foundation (CNCF).​
    • Project that was spun out of Google as an open source container orchestration platform. Builds on 15 years of experience at Google in a project called borg.​
    • Kubernetes is quickly becoming the new standard for deploying and managing software in the cloud. ​
    • Designed from the ground-up as a loosely coupled collection of components centered around deploying, maintaining and scaling workloads.​
    • Deploy your applications quickly and predictably​Scale your applications on the fly​
    • Seamlessly roll out new features​
    • Optimize use of your hardware by using only the resources you need
    • Kubernetes Architecture
      • Control Plane – controls the cluster and makes it function.  Consists of multiple components that can run on a single node or split across multiple nodes​
      • Each Node is managed by the Master. A Node can have multiple pods, and the Kubernetes master automatically handles scheduling the pods across the Nodes in the cluster. The Master’s automatic scheduling takes into account the available resources on each Node.​
      • Every Kubernetes Node runs at least:
      • Kubelet, a process responsible for communication between the Kubernetes Master and the Nodes; it manages the Pods and the containers running on a machine.​
      • A container runtime (like Docker) responsible for pulling the container image from a Registry, unpacking the container, and running the application.​
      • Pods
      • Kubernetes doesn’t run containers directly, instead it wraps one or more containers into a higher-level structure called a pod.
      • A runnable unit of work It can be just one container, or multiple related containers
      • Any containers in the same pod will share the same resources and local network.
      • Kubernetes connects pods to the network and the cluster environment. pods are scaled up and down as a unit,​
      • Master Node
      • API Server –  front-end of the cluster that services REST operations and connects to the etc database.​
      • Scheduler – schedules pods on specific nodes based on labels, taints and tolerations set for the pods. ​
      • Controller Manager – manages current state of the cluster.  Performs cluster-level functions, such as replicating components, keeping track of worker nodes, handling node failures, and so on​
      • Etcd:  A reliable distributed data store (B+tree key-value store) that persistently stores the cluster configuration
      • Worker Node
      • Kubelet – An agent that runs on each node in the cluster. It passes requests to the container engine to ensure that Pods are available​
      • Kube-proxy  – is a network proxy that runs on each node in your cluster, implementing part of the Kubernetes Service concept.​
      • Container Runtime – The container runtime is the software that is responsible for running containers. Kubernetes supports several container runtimes: Dockercontainerdcri-orktlet and any implementation of the Kubernetes CRI (Container Runtime Interface).​
      • Pods – Atomic unit or smallest “unit of work”of Kubernetes. They are logical groupings of Containers on a single host. A single Pod typically constitutes a working ‘app’

Deployment scenarios.

Labs

If you want to learn Docker and Kubernetes, seriously don’t waste your time reading documentation or searching ‘What is kubernetes’ it will just lead to to people explaining high level rubbish, if you want to learn the highly complex technology, guess what you need to get hands. Here is a plan;

  1. Run Docker example
  2. Run MiniKube
  3. Run Public Cloud

Kubernets Cheat sheets Commands


alias k=kubetcl
k version

kubectl delete pod nginx --grace-period=0 --force

if [ ! -d `/tmp ]; then mnkdir -p /~tmp; fi; while true; do echo$(date) >> ~/tmp/data.txt; sleep 5; done;

kubetcl describe pods |grep -C 10 "author-John Doe"
kubectl get pods -o yaml | grep -C 5 labels:

kubectl get pods -A | grep interset
kubectl -n ArcSight_Namespace logs -f InterSet_Analytcis_Pod_Name -c interset-analytics 3.	kubectl -n arcsight-installer-ojju3 logs -f interset-analytics-5c5db758c9-5xstw -c interset-analytics
gcloud container clusters get-credentials cluster-1 --zone eyrope-west2 - b --project acg1-206211
kubectl get pods -A | grep interset
kubeadmin config images pull
kubectl get all
kubectl get apiservices
kubetcl get nodes
kubectl get api-resources
kubectl get service, pod, deployment -n [namespace]
kubectl get namespace
kubectl config current-context
kubectl cluter-info

minikube version 
minikube start --wait=false

kubectl cluster-inf
kubectl get nodes

kubectl get pods
kubectl expose deployment first-deployment --port=80 --type=NodePort
export PORT=$(kubectl get svc first-deployment -o go-template='{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}')
echo "Accessing host01:$PORT"
curl host01:$PORT		

minikube addons enable dashboard
kubectl apply -f /opt/kubernetes-dashboard.yaml
kubectl get pods -n kubernetes-dashboard -w

~/.kube/config

—help

https://2886795283-30000-ollie07.environments.katacoda.com/

You can bootstrap a cluster as follows:

 1. Initializes cluster master node:

 kubeadm init --apiserver-advertise-address $(hostname -i) --pod-network-cidr 10.5.0.0/16


 2. Initialize cluster networking:

kubectl apply -f https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/kubeadm-kuberouter.yaml


 3. (Optional) Create an nginx deployment:

 kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/application/nginx-app.yaml


minikube version 
minikube start --wait=false

kubectl cluster-inf
kubectl get nodes

kubectl get pods
kubectl expose deployment first-deployment --port=80 --type=NodePort
export PORT=$(kubectl get svc first-deployment -o go-template='{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}')
echo "Accessing host01:$PORT"
curl host01:$PORT		

minikube addons enable dashboard
kubectl apply -f /opt/kubernetes-dashboard.yaml
kubectl get pods -n kubernetes-dashboard -w

~/.kube/config

—help

cdf-exec

kubectl get namesspaces
kubectl get nodes
kubectl describe node [node] | less

Tools

Research