KubernetesLabs icon indicating copy to clipboard operation
KubernetesLabs copied to clipboard

K8S Walkthrough code samples

profile for CodeWizard at Stack Overflow, Q&A for professional and enthusiast programmersVisitor BadgeLinkedin BadgeGmail BadgeOutlook Badge


Kubernetes Hands-on Repository

  • A collection of Hands-on labs for Kubernetes (K8S).
  • Each lab is a standalone lab and does not require to complete the previous labs.

Pre-Requirements

  • An existing cluster or any other local tool as described here
  • kubectl - The Kubernetes command-line tool, kubectl

Open in Cloud Shell

CTRL + click to open in new window


  • List of the labs in this repository:

:green_book: 00-VerifyCluster
:green_book: 01-Namespace
:green_book: 02-Deployments-Imperative
:green_book: 03-Deployments-Declarative
:green_book: 04-Rollout
:green_book: 05-Services
:green_book: 06-DataStore
:green_book: 07-nginx-Ingress
:green_book: 08-Kustomization
:green_book: 09-StatefulSet
:green_book: 10-Istio
:green_book: 11-CRD-Custom-Resource-Definition
:green_book: 12-Wordpress-MySQL-PVC
:green_book: 13-HelmChart
:green_book: 15-Prometheus-Grafana
:green_book: 16-Affinity-Taint-Tolleration
:green_book: 17-PodDisruptionBudgets-PDB
:green_book: 19-CustomScheduler
:green_book: 20-CronJob
:green_book: 21-KubeAPI


:green_book: 00-VerifyCluster

  • 01. Installing minikube
  • 02. Start minikube
  • 03. Check the minikube status
  • 04. Verify that the cluster is up and running
  • 05. Verify that you can "talk" to your cluster
    • 05.01. Verify that you can "talk" to your cluster

:green_book: 01-Namespace

  • 01. Create Namespace
    • 01.01. Create Namespace
  • 02. Setting the default Namespace for kubectl
  • 03. Verify that you've updated the namespace

:green_book: 02-Deployments-Imperative

  • 01. Create namespace
  • 02. Deploy multitool image
  • 03. Test the deployment
    • 03.01. Create a Service using kubectl expose
    • 03.02. Find the port & the IP which was assigned to our pod by the cluster.
    • 03.03. Test the deployment

:green_book: 03-Deployments-Declarative

  • 01. Create namespace
  • 02. Deploy nginx using yaml file (declarative)
  • 03. Verify that the deployment is created:
  • 04. Check if the pods are running:
  • 05. Update the yaml file with replica's value of 5
  • 06. Update the deployment using kubectl apply
  • 07. Scaling down with kubectl scale

:green_book: 04-Rollout

  • 01. Create namespace
  • 02. Create the desired deployment
  • 03. Expose nginx as service
  • 04. Verify that the pods and the service are running
  • 05. Change the number of replicas to 3
  • 06. Verify that now we have 3 replicas
  • 07. Test the deployment
  • 08. Deploy another version of nginx
  • 09. Investigate rollout history:
  • 10. Lets see what was changed during the previous updates:
  • 11. Undo the version upgrade by rolling back and restoring previous version
  • 12. Rolling Restart

:green_book: 05-Services

  • 01. Create namespace and clear previous data if there is any
  • 02. Create the required resources for this hand-on
  • 03. Expose the nginx with ClusterIP
  • 04. Test the nginx with ClusterIP
    • 04.01. Test the nginx with ClusterIP
    • 04.02. Test the nginx using the deployment name
    • 04.03. using the full DNS name
  • 05. Create NodePort
    • 05.01. Delete previous service
    • 05.02. Create NodePort Service
    • 05.03. Test the NodePort Service
  • 06. Create LoadBalancer (only if you are on real cloud)
    • 06.01. Delete previous service
    • 06.02. Create LoadBalancer Service
    • 06.03. Test the LoadBalancer Service

:green_book: 06-DataStore

  • 01. Create namespace and clear previous data if there is any
  • 02. Build the docker container
    • 02.01. write the server code
    • 02.02. Write the DockerFile
    • 02.03. Build the docker container
    • 02.04. Test the container
  • 03. Using K8S deployment & Secrets/ConfigMap
    • 03.01. Writing the deployment & Service file
    • 03.02. Deploy to cluster
    • 03.03. Test the app
  • 04. Using Secrets & config maps
    • 04.01. Create the desired secret and config map for this lab
    • 04.02. Updating the Deployment to read the values from Secrets & ConfigMap
    • 04.03. Update the deployment to read values from K8S resources
    • 04.04. Test the changes

:green_book: 07-nginx-Ingress

:green_book: 08-Kustomization

:green_book: 09-StatefulSet

  • 01. Create namespace and clear previous data if there is any
  • 02. Create and test the Stateful application
  • 03. Test the Stateful application
  • 04. Scale down the StatefulSet and check that its down
    • 04.01. Scale down the Statefulset to 0
    • 04.02. Verify that the pods Terminated
    • 04.03. Verify that the DB is not reachable
  • 05. Scale up again and verify that we still have the prevoius data
    • 05.01. scale up the Statefulset to 1 or more
    • 05.02. Verify that the pods is in Running status
    • 05.03. Verify that the pods is using the previous data

:green_book: 10-Istio

  • 01. Download latest Istio release (Linux)
  • 01.01 Add the istioctl client to your path (Linux or macOS):
    • 01.02. Install Istio
    • 01.03. Add the required label
    • 01.02. Install Kiali server
  • 02. Deploy the demo application
    • 02.01. Check the installation
    • 02.02. Verify that Istio is working

:green_book: 11-CRD-Custom-Resource-Definition

:green_book: 12-Wordpress-MySQL-PVC

:green_book: 13-HelmChart

:green_book: 15-Prometheus-Grafana

:green_book: 16-Affinity-Taint-Tolleration

:green_book: 17-PodDisruptionBudgets-PDB

  • 01. start minikube with Feature Gates
  • 02. Check Node Pressure(s)
  • 03. Create 3 Pods using 50 MB each.
  • 04. Check MemoryPressure

:green_book: 19-CustomScheduler

:green_book: 20-CronJob

:green_book: 21-KubeAPI

  • 01. Build the docker image
    • 01.01. The script which will be used for query K8S API
    • 01.02. Build the docker image
  • 02. Deploy the Pod to K8S
    • 02.01. Run kustomization to deploy
    • 02.02. Query the K8S API