Post

Kubernetes/Kind Tutorial

The Basics

This guide is aimed to fast-track your Kubernetes learning by focusing on a practical hands-on overview guide. When learning Kubernetes, you usually have an idea of some existing system you own and manage, or a website that you are building. The challenge is understanding which Kubernetes building blocks you need in order to run your workloads on Kubernetes

The problem: “I want to adopt Kubernetes”

The problem: “I have some common existing infrastructure”

Our focus: Solving the problem by learning each building block in order to port our infrastructure to Kubernetes.

Kubernetes Tools: kubectl

To manage and work with Kubernetes, you need kubectl Let’s grab that from here

Run Kubernetes Locally

  • Install kubectl to work with kubernetes

    We’ll head over to the kubernetes site to download kubectl

  • Install the kind binary

    You will want to head over to the kind site

  • Create a cluster

1
kind create cluster --image kindest/node:v1.27.2

Namespaces

1
kubectl create namespace test

Configmaps

1
2
3
kubectl -n test create configmap mysql --from-literal MYSQL_RANDOM_ROOT_PASSWORD=1

kubectl -n test get configmaps

Secrets

1
2
3
4
5
kubectl -n test create secret generic wordpress --from-literal WORDPRESS_DB_HOST=mysql --from-literal WORDPRESS_DB_USER=exampleuser --from-literal WORDPRESS_DB_PASSWORD=examplepassword --from-literal WORDPRESS_DB_NAME=exampledb

kubectl -n test create secret generic mysql --from-literal MYSQL_USER=exampleuser --from-literal MYSQL_PASSWORD=examplepassword --from-literal MYSQL_DATABASE=exampledb

kubectl -n test get secret

Deployments

Clone Kubernetes example yaml files for deployment, services, statefulset, and ingress.

1
2
kubectl -n test apply -f deploy.yaml
kubectl -n test get pods

Services

1
2
kubectl -n test apply -f service.yaml
kubectl -n test get svc

Storage Class

1
kubectl get storageclass

Statefulset

1
2
3
kubectl -n test apply -f statefulset.yaml

kubectl -n test get pods

Persistent Volumes

Port Forwarding

  • We can access private service endpoints or pods using port-forward :
1
2
kubectl -n test get pods
kubectl -n test port-forward <pod-name> 8080:80

Public Traffic

  • In order to make our site public, its common practise to expose web servers via a proxy or API gateway.

Ingress

  • To use an ingress, we need an ingress controller
1
2
3
4
5
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.3/deploy/static/provider/cloud/deploy.yaml

kubectl -n ingress-nginx get pods

kubectl -n ingress-nginx --address 0.0.0.0 port-forward svc/ingress-nginx-controller 8080:80
  • Create an Ingress
1
kubectl -n test apply -f ingress.yaml

Stop the Kind cluster

1
kind delete cluster --name kind
This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.