Kubernetes Fundamental
Kubernetes Fundamental
(v0.0.7)
last update: 2018/10/01
Sources from and thanks to Michael Hausenblas, Marko Lukša, Bob Killen
Presenter: Arash Kaffamanesh
About this project
● This k8s trainings slides are created for everyone who’d like to
use it for k8s fundamental trainings
● The video recording of one of our tainings is available here →
● GET STARTED, ingress point :-) is here →
● Additional study guides and training material will be developed
for CKA and CKAD Candidates →
● For more information please join us on slack →
○ If you’d like to become a CKA(D), please ask to join the
CKA(D)s channel, everyone in the group can add you to the
CKA(D)s channel
How to prepare for online trainings (1)
● Install minikube →
● Install minishift (OKD) →
● Install a k8s-vagrant-multi-node cluster →
● Or Kubeadm DinD Cluster →
● Optional: you need an account on GCP with billing enabled
○ Get started with $300 free credits →
○ Create a project and enable GKE service
○ Install gcloud SDK / CLI: →
Source: https://kubernauts.gitbooks.io/kubernauts-kubernetes-training-courses/content/courses/novice.html
How to prepare for online trainings (2)
Source: https://kubernauts.gitbooks.io/kubernauts-kubernetes-training-courses/content/courses/novice.html
Kubernetes Learning Resources List
Source: http://k8s.info/cs.html#cs-menu
Kubernetes Architecture (abstraction overview)
Source: http://k8s.info/cs.html#cs-menu
Kubernetes Architecture (abstraction details)
Source: http://k8s.info/cs.html#cs-menu
Kubernetes’ High-Level Architecture Overview
Source: https://www.weave.works/blog/what-does-production-ready-really-mean-for-a-kubernetes-cluster
Kubernetes Architecture Overview
● 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)
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
● 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"
Local Development Environment using Minikube
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
Source:
Create a Kubernetes cluster on AWS / OpenStack
Source:
Kubernetes API Groups, OpenAPI and Swagger UI (1)
Source: https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0
Kubernetes ingress with Ambassador
Source: https://blog.getambassador.io/kubernetes-ingress-nodeport-load-balancers-and-ingress-controllers-6e29f1c44f2d
Kubernetes by Example
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)
● 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
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: Cassandra on Kubernetes
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