Skip to content

darkxeno/kubernetes-workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kubernetes-workshop

A workshop for Kubernetes beginners

Requirements

  • A computer
  • Basic knowledge about docker
  • Recent docker version >= 18.06 (Docker -> Preferences -> Enable Kubernetes -> Apply)

NodeJS App Image versions

darkxeno/nodejs-pod:0.9.0 => no healthchecks

darkxeno/nodejs-pod:1.0.0 => healthchecks without db reconnect

darkxeno/nodejs-pod:1.1.0 => healthchecks with db reconnect

Nodes

Definition: machines part of the kubernetes cluster

Documentation

  • Master: kubernetes API server, nodes membership and metrics
  • Workers: workload placeholders (container runners)

Pods

Definition: Set of containers running on the same IP (shared network)

Usage: application layer

Pods Documentation

# kubectl apply -f manifest.yaml (creates or updates kubernetes entities)
# kubectl create -f manifest.yaml (creates kubernetes entities)
# kubectl describe resourceType resourceId (gets all the info about an entity / helps on troubleshooting ) ex: kubectl describe pod nodejs-pod-xxxx

kubectl apply -f nodejs-deployment.yaml
kubectl get pods
kubectl logs nodejs-deployment-xxx
  • Scale in / out the deployment, delete / fail one replica pod
kubectl scale deployment nodejs-deployment --replicas=0
kubectl scale deployment nodejs-deployment --replicas=6
  • Delete one pod
kubectl delete pod ...

Services

Definition: A way to expose endpoints and make them discoverable (internally / externally, "like" a round robin DNS entry)

Documentation

TYPES

ClusterIP: the port is open through an virtual ip that allows internal k8s access

NodePort: the same static port is open on all the nodes, allows access from k8s or node processes

LoadBalancer: the port is open and balanced to all the nodes to allow external access

Headless: same as clusterIP by without IP, only DNS entry

ExternalName: only a DNS entry is added to the service (CNAME)

  • Create a service using the template
  • Check services / endpoints
kubectl get services
kubectl get endpoints
  • Consume the service
curl -X POST 127.0.0.1:3000 -H "Content-Type:application/json" -d '{"test":true}'
open browser at:  localhost:3000
  • Fail one pod using the service (end process)
curl localhost:3000/exit

Statefulsets

Definition: Stateful ordered pods with persistent storage. (distributed databases)

Usage: state layer

Documentation

  • Create a statefulset + service with the template (Docker image: darkxeno/mongodb-statefulset:4.1.3)
kubectl get statefulsets
kubectl get pods

Health checks

Definition: A way to verify and control the correct working status of a pod

Types: Readyness and liveness probes

Documentation

  • Add a readiness healthcheck [GET /is-ready] (check template)
  • Add a liveness healthcheck [GET /is-alive]
  • Release a new nodejs app version (change image on the template to: docker.io/darkxeno/nodejs-pod:1.0.0)
  • See how the rolling update works and the how the state of the pods changes
watch -n 1 kubectl get pods
  • Disconnect one pod from mongodb and see how the status changes
curl localhost:3000/disconnect

Fault tolerance

  • Release a new nodejs app version (change image on the template to: docker.io/darkxeno/nodejs-pod:1.1.0) supports auto-reconnect
  • Simulate a db failure (delete service and delete mongodb pod)
kubectl delete service ...
kubectl delete pod ...
  • See how the state of the pods changes
watch -n 1 kubectl get pods
  • Test service downtime
curl localhost:3000
  • Recover the db service
kubectl apply -f [mongodb-xxx.yaml]

[Extra] Statefulset persistent storage

  • Have a look on the volumeClaimTemplates and volumeMounts fields on the template
  • Deploy the template and check the volumes

NOTE: statefulsets needs to be delete in order to be updated

kubectl get pvc
kubectl get pv

[Extra] Configmaps and Secrets

Definition: tools to provide additional configuration or credentials to the pods NOTE: statefulsets needs to be delete in order to be updated

  • Create a configmap for DB configuration
kubectl apply -f ./configmaps/mongodb-configmap.yaml
  • Configure the pods to use the configmap template
kubectl apply -f ./statefulsets/mongodb-statefulset-with-config-map.yaml
  • Verify the config on the pod
kubectl exec -ti mongodb-0 cat /data/configdb/mongo.conf
  • [exercise] create a secret for db authentication

[Extra] Kubernetes dashboard

  • Deploy the kubernetes dashboard
kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
kubectl proxy
  • Navigate to dashboard

  • Select the kubeconfig file at ~/.kube/config or SKIP

About

A workshop for Kubernetes beginners

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published