Kubernetes
Kubernetes
v0.15.1
last update: 2020/06/15
Latest Updates
● June 15.
○ Kubernetes Sequence Diagram added →
● June 14.
○ The Pod Cheat Sheet →
Latest Updates
● June 1.
○ Get Started with RSaaS →
● May 18.
○ New Self Learning Site →
● April 1.
○ Troubleshooting →
● Feb. 15.
○ Headless Service vs. ClusterIP →
● Feb. 10.
○ Practical Kubernetes Problems →
● Jan. 27.
○ Cloud Native Storage on K8s →
Get Started with RSaaS
Rancher Shared as Service
and Bonsai, for free, forever!
https://youtu.be/5JitQlS6gmM
Deploy Rancher Kubernetes
Engine on your local
machine through RSaaS
https://youtu.be/Xc8rEUUn6Bk
About this project
Source: https://kubernauts.gitbooks.io/kubernauts-kubernetes-training-courses/content/courses/novice.html
How to prepare for trainings (2)
● Other options:
○ Rancher k3d / k3s →
○ Rancher rke →
○ Multipass Rancher →
○ Multipass Kubeadm →
○ Multipass k3s → (prefered for training)
○ tk8ctl →
■ TK8 Cattle AWS →
■ TK8 Cattle EKS →
How to prepare for trainings (3)
Source: https://kubernauts.gitbooks.io/kubernauts-kubernetes-training-courses/content/courses/novice.html
Kubernetes Learning Resources List
https://www.mindmeister.com/929803117/container-ecosystem?fullscreen=1
Agenda
Agenda, day 1
● Agenda
○ What is Kubernetes
○ Deployment and release strategy (in short)
○ Getting started (general)
○ Security
○ Exercises
○ more Exercises
Agenda, day 2
● Agenda
○ HA Installation and Multi-Cluster Management
○ Tips & Tricks, Practice Questions
○ Advanced Exercises
■ Load Testing on K8s with Apache Jmeter
■ Kafka on K8s with Strimzi and Confluent OS
■ TK8 Cattle AWS vs. Cattle EKS
■ TK8 Special with TK8 Web
○ TroubleShooting & Questions
What is Kubernetes?
What Is Kubernetes?
Source: https://kubernetes.io/docs/concepts/overview/components/#master-components
A Typical Flow: How K8s API works
Source: https://blog.heptio.com/core-kubernetes-jazz-improv-over-orchestration-a7903ea92ca
Kubernetes Component Flow
Source: https://medium.com/payscale-tech/imperative-vs-declarative-a-kubernetes-tutorial-4be66c5d8914
Kubernetes Component Flow
Source: https://medium.com/cloud-heroes/exploring-the-flexibility-of-kubernetes-9f65db2360a0
Kubernetes Architecture Overview
Source: https://www.weave.works/blog/what-does-production-ready-really-mean-for-a-kubernetes-cluster
Kubernetes’ High-Level Architecture Overview
Kubernetes Architecture 101
Source: https://www.aquasec.com/wiki/display/containers/Kubernetes+Architecture+101
Kubernetes is like Kafka: Event-Driven Architecture
● Pod →
● Label and selectors →
● Controllers
○ Deployments →
○ ReplicaSet →
○ ReplicationController →
○ DaemonSet →
● Service →
Core Concepts of Kubernetes (2)
● StatefulSets →
● ConfigMaps →
● Secrets →
● Persistent Volumes (attaching storage to containers) →
● Life Cycle of Applications in Kubernetes →
○ Updating Pods
○ Rolling updates
○ Rollback
Kubernetes resources explained (1)
Deploying Pod (po) [v1] The basic deployable unit containing one or more processes
Workloads in co-located containers
DaemonSet Runs one pod replica per node (on all nodes or only on
those matching a node selector)
StatefulSet
Runs stateful pods with a stable identity
Deployment
Declarative deployment and updates of pods
The Pod Cheat Sheet
Services Service (svc) [v1] Exposes one or more pods at a single and stable IP
address and port pair
Endpoints (ep) [v1]
Defines which pods (or other servers) are exposed
through a service
Ingress (ing) [extensions/v1beta1] Exposes one or more services to external clients through
a single externally reachable IP address
Config ConfigMap (cm) [v1] A key-value map for storing non-sensitive config options
for apps and exposing it to them
Storage PersistentVolume* (pv) [v1] Points to persistent storage that can be mounted into a
pod through a PersistentVolumeClaim
PodDisruptionBudget (pdb) Defines the minimum number of pods that must remain
[policy/v1beta1] running when evacuating nodes
Resources LimitRange (limits) [v1] Defines the min, max, default limits, and default requests
for pods in a namespace
● Kubernetes.IO documentation →
● Get started with k8s w/o installation with Katacoda →
● Kubernetes Bootcamp →
● Install Kubernetes CLI kubectl →
● Create a local cluster with
○ Docker For Desktop →
○ Minikube →
○ MiniShift →
○ DinD → or Kind →
Local Development Environment using Minikube
● alias k="kubectl"
● alias g="gcloud"
● alias kx="kubectx"
● alias kn="kubens"
● alias kon="kubeon"
● alias koff="kubeoff"
● alias kcvm="kubectl config view --minify"
● alias kgn="kubectl get nodes"
● alias kgp="kubectl get pods"
Kubectl commands, Cheat Sheets
● Again: use kubectx and kubens, it makes the life easier :-)
● A great Cheat Sheet by Denny Zhang →
● Kubectl: most useful commands by Matthew Davis →
Create a Kubernetes cluster on GKE (1)
Source:
Create a Kubernetes cluster on GKE (2)
Note: deleting a cluster doesn’t delete your storage / disks on GKE, you’ve to delete them manually
Create a Kubernetes cluster on AWS
Source:
Kubernetes API Groups, OpenAPI and Swagger UI (1)
$ kubectl api-versions
Source: https://akomljen.com/kubernetes-api-resources-which-group-and-version-to-use/
Play with Simple Apps on Kubernetes
Source: https://medium.com/@metaphorical/internal-and-external-connectivity-in-kubernetes-space-a25cba822089
Understanding Kubernetes NodePort vs LoadBalancer vs Ingress (2)
Source: https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0
Shedding Light on Managing External Access to the Services
Source: https://blog.getambassador.io/kubernetes-ingress-nodeport-load-balancers-and-ingress-controllers-6e29f1c44f2d
Understanding Kubernetes Networking (I)
Source: https://itnext.io/an-illustrated-guide-to-kubernetes-networking-part-1-d1ede3322727
Understanding Kubernetes Networking
Source: https://medium.com/devopslinks/kubernetes-headless-service-vs-clusterip-and-traffic-distribution-904b058f0dfd
Kubernetes Headless vs. ClusterIP and traffic distribution
client client
https://github.com/arashkaffamanesh/practical-kubernetes-problems#headless-services-for-stickiness
Ingress Controller (Traefik)
DNS client
/etc/hosts
192.168.64.23
1- Client looks up
my.ghost.svc 2- Client sends
HTTP GET req.
to controller with
my.ghost.svc
In host header
Understanding Kubernetes Networking (II)
Source: https://medium.com/@tao_66792/how-does-the-kubernetes-networking-work-part-1-5e2da2696701
Understanding Kubernetes Networking (III)
Source: https://medium.com/google-cloud/understanding-kubernetes-networking-pods-7117dd28727
MetallB
● How can you have same experience of using a load balancer service
type on your bare metal cluster just like public clouds?
● This is what Metallb aims to solve.
● Layer 2/ARP mode: Only one worker node can respond to the Load
Balancer IP address
● BGP mode: This is more scalable, all the worker nodes will respond
to the Load Balancer IP address, this means that even of one of the
worker nodes is unavailable, other worker nodes will take up the
traffic. This is one of the advantages over Layer 2 mode but you
need a BGP router on your network (open source routers Free
Range Router, Vyos)
Source: https://metallb.universe.tf/
MetallB
Source: https://github.com/cloudnativelabs/kube-router/blob/master/docs/user-guide.md#advertising-ips
MetallB Sample ARP Mode Configmap
apiVersion: v1
kind: ConfigMap
metadata:
name: config
data:
config: |
address-pools:
- name: my-ip-space
protocol: layer2
addresses:
- 84.200.xxx.xxx-84.200.xxx.xxx
MetallB Sample BGP Mode Configmap
Security
Best Practices (I)
Source: https://blog.kubernauts.io/kubernetes-best-practices-d5cbef02fe1b
Managing Secrets in Kubernetes
Source: https://blog.kubernauts.io/managing-secrets-in-kubernetes-with-vault-by-hashicorp-f0db45cc208a
Exercises
kubectl cheat sheet
kubectl cheat sheet
→ https://github.com/dennyzhang/cheatsheet-kubernetes-A4
Source:
Exercise 1: Create a deployment for nginx ...
Source:
Exercise 1: Create a deployment for nginx ...
$ cat nginx.yaml
● Create the deployment with a manifest: apiVersion: extensions/v1beta1
○ kubectl create -f nginx.yaml kind: Deployment
metadata:
name: nginx
Note: Pods, services, configmaps, secrets in our examples are labels:
app: nginx
all part of the /api/v1 API group, while deployments are part of spec:
the /apis/extensions/v1beta1 API group. replicas: 2
selector:
The group an object is part of is what is referred to as apiVersion matchLabels:
in the object specification, available via the API reference. app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.12.2
ports:
- containerPort: 80
Exercise 1: Create a deployment for nginx ...
● k get svc
Exercise 2: write an ingress rule ...
Note: the kubia image is from the Kubernetes in Action book by Marko Lukša
Exercise 4: horizontal pod autoscaling (hpa)
… another pod?
Exercise 4: horizontal pod autoscaling (hpa)
● On GKE:
Note: This example is from the Chapter 10 of the Kubernetes in Action book by Marko Lukša
Exercise 6: Play with RBAC
minikube stop
minikube start --extra-config=apiserver.Authorization.Mode=RBAC
k create ns foo
k create ns bar
k run test --image=luksa/kubectl-proxy -n foo
k run test --image=luksa/kubectl-proxy -n bar
k get po -n foo
k get po -n bar
k exec -it test-xxxxxxxxx-yyyyy -n foo sh
k exec -it test-yyyyyyyyy-xxxxx -n bar sh
curl localhost:8001/api/v1/namespaces/foo/services
curl localhost:8001/api/v1/namespaces/bar/services
cd Chapter12/
cat service-reader.yaml
k create -f service-reader.yaml -n foo
k create role service-reader --verb=get --verb=list --resource=services -n bar
k create rolebinding test --role=service-reader --serviceaccount=foo:default -n foo
k create rolebinding test --role=service-reader --serviceaccount=bar:default -n bar
k edit rolebinding test -n foo
k edit rolebinding test -n bar
Note: This example is from the Chapter 12 of the Kubernetes in Action book by Marko Lukša
Practical K8s Problems
https://github.com/arashkaffamanesh/practical-kubernetes-problems
Tips & Tricks
Tips & Tricks (I)
https://learnk8s.io/troubleshooting-deployments
K8s Practice Questions
Practice Questions (I)
● Deploy a default Network Policy for each resources in the default namespace to deny
all ingress and egress traffic.
● Create a pod that contain multiple containers : nginx, redis, postgres with a single
YAML file.
● Deploy nginx application but with extra security using PodSecurityPolicy
● Create a Config map from file.
● Create a Pod using the busybox image to display the entire content of the above
ConfigMap mounted as Volumes.
● Create configmap from literal values
● Create a Pod using the busybox image to display the entire ConfigMap in
environment variables automatically.
● Create a ResourceQuota in a namespace "kube-cologne" that allows maximum of
Practice Questions (III)
Source: https://kubernauts.slack.com/archives/G6CCNMVKM/p1562305149191600
Advanced Exercises
Exercise 7: Load Testing with Apache Jmeter on Kubernetes and OpenShift
● TK8 on Github:
https://github.com/kubernauts/tk8
Exercise 9: Kafka Confluent on Kubernetes or OpenShift
● Github link:
○ https://github.com/kubernauts/kafka-confluent-platform
Exercise 10: Strimzi Kafka Operator
● Github link:
○ https://github.com/strimzi/strimzi-kafka-operator
● Cassandra Operator →
Get in Touch
1. Slack - https://kubernauts-slack-join.herokuapp.com/
2. #kubernetes-teachers on https://kubernetes.slack.com
3. GitHub - https://github.com/kubernauts
4. Twitter - @kubernauts
5. Meetup group - https://www.meetup.com/kubernauts/
6. And finally, kubernauts.io, kubernauts.de &
kubernauts.academy (coming in Q3 / 19)
Tooling and Helpers
Here you go:
The Golden Kubernetes Tooling and Helpers list
Cloud Native Storage
Cloud Native Storage on Kubernetes®
Need Training On-Site?
https://kubernauts.de
Kubernauts’ Kubernetes
Online Training
on July 2nd and 3rd
https://kubernauts.de/en/training/index.htmlkubernetes-training-course.html
We Love To Learn From You, Join Us, We’re Hiring!
https://kubernauts.de/en/careers/