How Kubernetes works? (II)

In the previous part we talked about K8s architecture. In this post we talk about running a cluster and deploying an app to it.

We are going to get started with K3s which is a lightweight version of K8s. It only contains the main components of Kubernetes. Since I don’t have a network of VMs or physical machines, I’m going to use K3d which is a wrapper for running K3d in docker containers. Please make sure you have installed docker and K3d in your computer. As we talked a in the previous post a cluster consists of some leader nodes and some worker nodes. To create a cluster with 2 workers and 1 leader you can run this K3d command.

$ k3d cluster create --no-lb -a 2

After that you can veiw the docker containers created for workers and leader with docker ps. There should be 5 containers running, 2 for worker nodes, one for leader, and one for k3d tools. You can see that agent node has opened port 49209 and we will use that port to access the leader. If you run the create command without --no-lb then a load balancer is created for load balancing requests to the agents with port 6443. You can also view the nodes using kubectl get nodes and cluster info with kubectl cluster-info. Furthermore you have start, stop, delete commands in k3d to manage the cluster.

$ kubectl get nodes              
NAME                       STATUS   ROLES                  AGE   VERSION
k3d-k3s-default-agent-0    Ready    <none>                 5s    v1.27.4+k3s1
k3d-k3s-default-agent-1    Ready    <none>                 6s    v1.27.4+k3s1
k3d-k3s-default-server-0   Ready    control-plane,master   9s    v1.27.4+k3s1
$ docker ps                      
CONTAINER ID   IMAGE                            COMMAND                  CREATED          STATUS          PORTS                     NAMES
a80937cced69   ghcr.io/k3d-io/k3d-tools:5.6.0   "/app/k3d-tools noop"    18 seconds ago   Up 17 seconds                             k3d-k3s-default-tools
f47d6b7868f0   rancher/k3s:v1.27.4-k3s1         "/bin/k3d-entrypoint…"   18 seconds ago   Up 12 seconds                             k3d-k3s-default-agent-1
8628b3578204   rancher/k3s:v1.27.4-k3s1         "/bin/k3d-entrypoint…"   18 seconds ago   Up 12 seconds                             k3d-k3s-default-agent-0
4da8e3e6d566   rancher/k3s:v1.27.4-k3s1         "/bin/k3d-entrypoint…"   18 seconds ago   Up 16 seconds   0.0.0.0:49209->6443/tcp   k3d-k3s-default-server-0
$ kubectl cluster-info
Kubernetes control plane is running at https://0.0.0.0:49209
CoreDNS is running at https://0.0.0.0:49209/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://0.0.0.0:49209/api/v1/namespaces/kube-system/services/https:metrics-server:https/proxy

One response to “How Kubernetes works? (II)”

  1. I’d like to find out more? I’d love to find out more details.