Step 10: Cluster deployment and checks

In short
  • Running the xkub_30_cluster.yml playbook from WSL, then running it again to check idempotence.
  • Checks on the first control plane: containerd and crictl, kubeadm-config.yaml, cilium-values.yaml, static pods, and admin kubeconfig.
  • First kubectl commands: nodes Ready, labels, taints DMZ, pods, and focus on CoreDNS (replicas, podAntiAffinity, tolerations).
  • Health of etcd (leader, quorum RAFT), Cilium (status, connectivity test), and the API kube-vip VIP.

Introduction

Now is the time to take action.

The previous articles described the content of the Ansible playbook xkub_30_cluster.yml, detailing each role called:

  • xkub_kube_vip: deployment of the solution responsible for access to the K8S API and its high availability, distributed across the three cluster controller instances.
  • xkub_kubeadm_init: initialization of the first cluster controller with the deployment of basic components through static pods and using kubeadm.
  • xkub_kubeadm_join: adding all nodes, distinguishing between cluster controllers and worker nodes.
  • xkub_cilium: deployment via Helm of the Cilium CNI (Container Network Interface).

With each description of the actions, we took the opportunity to explore some theory and explain certain key principles related to each of these steps.

Now is the time to launch this famous playbook so that the magic can happen and produce a Kubernetes cluster ready for use.

Launching the playbook

To do this, it's very simple, as we rely on the Ansible layer deployed in my WSL instance from my W11 workstation. Feel free to review the logic to be comfortable with the commands and the Ansible directory structure used.

ansible-playbook playbooks/xkub_30_cluster.yml

The playbook will be executed, calling role after role to apply them to the appropriate targets from the inventory.

At this stage, I would like to remind you that the HAproxy load balancers have already been deployed. Therefore, all K8S nodes will be affected, with a focus on the first control plane, prdk8sgru501, as it will be used to establish the initial configuration of the cluster. All other nodes will then simply join this node to form the entire cluster.

We are now going to run the command.

Running the xkub_30_cluster.yml playbook from WSL: kube-vip play on the three control planes

Click the image to enlarge.

We can follow all the actions that are performed. These actions will take several minutes to execute, but within fifteen minutes, we should see the final report displayed by Ansible without encountering any errors.

Tasks of the xkub_kubeadm_init role: kubeadm configuration file, kubeadm init, and copy of the admin kubeconfig

Click the image to enlarge.

kube-vip switching back to admin.conf, then start of the kubeadm join play

Click the image to enlarge.

Tasks of the xkub_kubeadm_join role: join the control planes CP2/CP3, then the workers

Click the image to enlarge.

Tasks of the xkub_cilium role: installation of Helm, the helm-diff plugin, cilium-cli, and the Cilium chart

Click the image to enlarge.

PLAY RECAP of the first execution of the xkub_30_cluster.yml playbook with no errors

Click the image to enlarge.

Running the playbook again

However, it is not enough to perform only one execution. As I have said many times, correct Ansible code is idempotent code, meaning that it can be replayed without risk once the changes have been applied.

That is what we are going to do.

Second execution of the xkub_30_cluster.yml playbook: the kube-vip tasks are reported as 'ok'

Click the image to enlarge.

This time, the process should be faster, and the final summary should contain no changes. Unfortunately, this is not the case for me, as I still see a modification displayed, apparently related to Cilium. This is a correction that I should make, but let's say that at this stage, it is not too serious, and in any case, the playbook can be relaunched without errors.

PLAY RECAP of the second execution: only one change remains, on the Cilium Helm chart

Click the image to enlarge.

Checks on the first control plane

Normally, the cluster is operational, but we still need to verify everything. This is also an opportunity to talk about some fundamentals and to initiate your first interactions with this new K8S cluster.

We will therefore initially focus on a set of commands that we will execute manually on the first control plane by connecting via SSH (using the same account as used by Ansible).

In practice, we very rarely access one of the control planes directly. These operations are reserved for maintenance or incidents, or, as here, for initial tests before putting the cluster into production.

In the future, we will always access the API remotely via secure connection points, such as a bastion or dedicated work environments reserved for administrative access to the cluster. It is important to note that API access is very sensitive, and it is crucial to define access methods within the company. We will then need to leverage the RBAC (Role-Based Access Control) features of K8S to grant the correct permissions to the right people. We will have an opportunity to discuss this further, but you can already consult my article on the subject.

We are now in the shell of the first control plane.

The containerd runtime

First, we will check if containerd is running and operational. It was a prerequisite for K8S because, as a reminder, K8S does not offer a container execution engine, but it interfaces with a CRI (Container Runtime Interface) compatible runtime, of which the containerd/crun combination is part. Feel free to also consult the section dedicated to this topic in the presentation of the architecture chosen for this cookbook.

To do this, a simple sudo systemctl status containerd command will suffice to verify that the service is active. Ideally, we could do this on each node.

Command systemctl status containerd: the containerd service is active on prdk8sgru501

Click the image to enlarge.

We will go a little further with the crictl command. Remember, we integrated it into the xkub_k8s_prereqs role during the installation of Containerd. Similar to the classic docker command, we can query the runtime without using kubectl commands.

sudo /usr/local/bin/crictl info

This command provides us with status information and detailed configuration of the engine. Everything seems correct at this level.

Output of crictl info: CNI configuration loopback and cilium runtime

Click the image to enlarge.

Next, we run sudo /usr/local/bin/crictl ps -a

sudo /usr/local/bin/crictl ps -a

We then obtain a list of all containers present on the node. We can already see our images associated with the Kubernetes base layers, such as the API Server, ETCD, and the scheduler.

Output of crictl ps -a: etcd, kube-apiserver, kube-scheduler, kube-vip containers, and Cilium init containers in the Exited state

Click the image to enlarge.

You will also notice stopped containers, mainly related to Cilium. This is normal at this stage because, during the deployment of Cilium and other components, it is possible that temporary containers are deployed to perform tests or specific configurations. We often talk about "init" containers that prepare the ground for the next steps and then simply terminate once their task is complete.

Configuration files

We can continue our exploration. This time, we will perform a small check of our Kubernetes configuration driven by Ansible.

Remember that this was deployed in a YAML file derived from a Jinja template and placed in /etc/kubernetes/

Therefore, we can view its contents

sudo cat /etc/kubernetes/kubeadm-config.yaml
Contents of the /etc/kubernetes/kubeadm-config.yaml file generated by Ansible: version 1.36.5, podSubnet 10.11.0.0/16, serviceSubnet 10.12.0.0/16, and certSANs

Click the image to enlarge.

Indeed, our desired version of Kubernetes is indeed located here, as indicated in the file "versions.yml" which is located in the folder "group_vars\clu_k8s_xkub" within the "inventory" directory on my workstation. It's possible that the version has changed since the initial writing of the first article, due to the time that may elapse between different stages of writing. Don't focus on this.

Important elements that are also present include the subnets associated with our pods (10.11.0.0/16) and our services (10.12.0.0/16), as well as any name that might be associated with the certificate used by the API.

It is this file, pushed by Ansible, that was subsequently read by kubeadm during the execution of the xkub_kubeadm_init role to define the configuration of our cluster.

Let's do the same with the Cilium configuration, which should also appear in /etc/kubernetes/, but through the file cilium-values.yaml.

Contents of the /etc/kubernetes/cilium-values.yaml file: kubeProxyReplacement, k8sServiceHost 192.168.10.121, and pool 10.11.0.0/16

Click the image to enlarge.

Here too, Ansible has done its job, and the configuration is consistent with our expectations, with a reference to the IP used as the VIP for accessing the k8s API, as well as the address pool for our pods (10.11.0.0/16).

Static pods

Another interesting observation is to take a look at the directory /etc/kubernetes/manifests, because that's where you'll find our so-called static pods, which are the pods monitored by the kubelet agent available on each node.

Contents of the /etc/kubernetes/manifests directory: etcd, kube-apiserver, kube-controller-manager, kube-scheduler, and kube-vip

Click the image to enlarge.

We can find all the YAML files related to the fundamentals of a Kubernetes cluster there

  • etcd: This is the key-value store that is replicated between each control plane and contains the entire cluster configuration
  • apiserver: the entry point for interacting with the cluster
  • controller-manager: This Kubernetes component is responsible for ensuring that the actual state of the cluster matches the desired state
  • scheduler: The Kubernetes component responsible for deciding which node a new pod should run on.
  • kube-vip: This is the only component that is not part of the default set, but it corresponds to our choice of managing the API's virtual IP (VIP) with this solution (associated with the role xkub_kube_vip).

It is important to understand that when kubeadm was called, it used the configuration file passed as an argument to generate these YAML files (excluding kube-vip), so that they could then be managed by the kubelet, which could execute the components. These files are critical and can be edited directly to modify the cluster's configuration. Furthermore, with each modification, the associated components are automatically restarted by the kubelet.

First kubectl commands

Finally, let's move on to running our first kubectl commands, which is the official command-line interface for Kubernetes.

This will use the config file located in the profile of our user in the hidden directory .kube/

cat .kube/config
Contents of the .kube/config file for the ansible-windows account, with certificates and private key masked

Click the image to enlarge.

This file contains the connection details for the cluster, starting with the API URL (https://xkub.coolcorp.priv:6443), as well as the associated certificate and the private key of the user to access the K8S configuration through the API.

This configuration was also generated during the execution of the role xkub_kubeadm_init and the call to kubeadm. It covers access to the cluster in cluster admin mode, which is the highest level of authorization that allows you to do anything you want on the cluster. Its content is therefore extremely critical and must be handled with care. We are currently in a post-deployment phase where we are carefully monitoring operations. However, in a production environment, it is best to avoid directly using this file on the controller that was used to start the cluster, unless there is an emergency.

Nodes, labels, and taints

Nevertheless, this allows us to check the status of the nodes with the command "kubectl get node"

kubectl get node
Output of kubectl get node: The seven nodes in the cluster are in a Ready state, including control-plane, worker-lan, and worker-dmz

Click the image to enlarge.

Very good news. All the servers are in the "Ready" state. At this stage, we can already identify the control plane and the workers, and for the latter, we have a distinction based on their location on the network. This proves that the labels have been applied.

We can also check them more thoroughly with the command "kubectl get nodes --show-labels"

kubectl get nodes --show-labels
Output of kubectl get nodes --show-labels: The network=lan and network=dmz labels are applied to the worker nodes

Click the image to enlarge.

Everything is there, and it is thanks to the ansible k8s module used in the role "xkub_kubeadm_join" that these labels could be applied.

Remember, we wanted not only labels but also taints. Feel free to review the section that discusses them to fully understand the difference between the two and why we use them.

We also check these with the command kubectl describe nodes | grep -E "Name:|Taints:"

kubectl describe nodes | grep -E "Name:|Taints:"
Taints on the nodes: control-plane:NoSchedule on the control planes and network=dmz:NoSchedule on the DMZ workers

Click the image to enlarge.

We have our taints on the nodes in the DMZ, which will be very useful to prevent components from ending up in the DMZ without us explicitly requesting it.

Resources and pods

Let's continue with the command kubectl get all -A.

kubectl get all -A
Output of kubectl get all -A: List of pods in the kube-system namespace

Click the image to enlarge.

Continued output of kubectl get all -A: Services, daemonsets, deployments, and replicasets

Click the image to enlarge.

The output is substantial because we are asking the API to list all resources (all) for all namespaces (-A).

Be careful, though: "all" is misleading, since the API only returns the main object types: pods, deployments and services. Still, that's already quite a lot, especially in the kube-system namespace, which, as a reminder, is the default namespace where all the critical components of the cluster live. We can access it because, as mentioned earlier, we are using admin access for the API calls.

So far, so good: all our pods are in the desired state. We can focus on them with the command kubectl get pod -A

kubectl get pod -A
Output of kubectl get pod -A: Columns READY, STATUS, and RESTARTS for all pods in the cluster

Click the image to enlarge.

The READY column is particularly interesting because it indicates, for each pod, how many containers are running out of the expected number. This is an opportunity to discuss the concept of a pod. I won't go into detail; everything is explained in this definition, but a pod can reference multiple containers. For example, in this screenshot, the pod "hubble-ui-865d8bd5cf-lq7sj" contains two containers within the pod, and both are running.

Currently, this is excellent: all containers of all pods are started, and we have not seen any restarts (which could indicate a problem).

Focus on key components

CoreDNS

Let's focus on some key components that we haven't talked about yet: DNS

As explained in previous articles, especially when we introduced the xkub_cilium role and discussed networking, Kubernetes comes with an internal resolution managed by core-dns.

Therefore, we find at least two instances of CoreDNS on the cluster

kubectl get pod -n kube-system -o wide | grep dns
The two CoreDNS pods in the cluster, both running on the prdk8smin502 worker node

Click the image to enlarge.

The -o wide option allows us to obtain the names of the nodes on which these pods are currently running, and they are not part of the control plane. Indeed, core-dns is allowed to run on the worker nodes… but thanks to our taints, as we discussed previously, the orchestrator can only use nodes within the LAN.

However, there is a subtlety: the CoreDNS configuration is not included in a manifest within the static pods, but it is written directly into Etcd during cluster initialization.

We can see the details of the deployment by directly accessing the content of the associated configuration using the following command

kubectl get deployment -n kube-system -l k8s-app=kube-dns -o yaml

This command allows us to cross-reference the configuration of the deployment associated with the label k8s-app=kube-dns in the namespace kube-system with an output (-o) in YAML format.

The API consults the etcd database and provides us with the characteristics of the requested object.

CoreDNS deployment in YAML format: 2 replicas and the podAntiAffinity rule preferredDuringSchedulingIgnoredDuringExecution is set

Click the image to enlarge.

Without going into detail at this stage, this type of command is very useful for obtaining the configuration of any Kubernetes object, or even for reconstructing the YAML files to potentially modify them and then redeploy the component.

For example, here we can see that a replica count of 2 was requested… we could increase it to three if we deem it necessary. We can also see that no toleration is associated with our taints on the nodes in the DMZ, so there is no risk of DNScore pods ending up there. Another interesting thing is that we observe a podAntiAffinity configuration, which here provides a rule to avoid DNS pods being placed on the same node to improve resilience in case of server failure.

However, if we look at the output of the previous command (kubectl get pod -n kube-system -o wide | grep dns), both pods are located on prdk8smin502.coolcorp.priv: why? Because the rule is in "best effort" mode… it's not an obligation, but it's recommended.

Furthermore, let's try to stop one of the pods… something to avoid in production, of course… but since there are two active ones, stopping one should not have any impact

We can do this with the command: kubectl delete pod coredns-589f44dc88-dsmpd -n kube-system (here I took the name of the pod as it appears in the listing, but this name is dynamic and changes each time it's instantiated).

kubectl delete pod coredns-589f44dc88-dsmpd -n kube-system
Deleting the coredns-589f44dc88-dsmpd pod using kubectl delete pod

Click the image to enlarge.

If I try to observe the DNS pods again

kubectl get pod -n kube-system -o wide | grep dns
A new CoreDNS pod recreated by the deployment 53 seconds ago on the prdk8sgru502 control plane node

Click the image to enlarge.

I still have two pods, but one appeared only a few seconds ago. This is normal: I stopped the pod, but not the deployment that controls it and says "I always want 2" via the replicas option. The cluster's controller component did its job and immediately restarted a pod... The scheduler took the podAntiAffinity rule into account and, this time, was able to start the new pod on prdk8sgru502.coolcorp.priv, a different node from prdk8smin502.coolcorp.priv, where the first pod already runs.

Why did it choose a controller as the server? Simply because, unlike our configuration on nodes in the DMZ, the DNS core deployment configuration actually tolerates running on a controller.

Tolerations for the CoreDNS deployment: CriticalAddonsOnly and node-role.kubernetes.io/control-plane NoSchedule

Click the image to enlarge.

If you have followed this cookbook so far, then you should be able to connect everything we've seen and start to understand how Kubernetes works at its core, even without going into detail.

The etcd database

Let's continue with another key component: the etcd database. This is often one of the causes of incidents in Kubernetes. It requires you to have at least three control plane nodes to ensure high availability for the entire system. It also implies significant network constraints between the control planes, since these must replicate the database; for this replication to work well, very low latency is required... That's why, even if it may seem like a good idea, distributing your controllers across various hosts connected by networks other than local ones can create problems.

Using the command "kubectl get pod -n kube-system -o wide | grep etcd", we can see that we have one etcd instance (pod) per control plane

kubectl get pod -n kube-system -o wide | grep etcd
One etcd pod per control plane: prdk8sgru501, prdk8sgru502, and prdk8sgru503

Click the image to enlarge.

We can go further and specifically check the status of these etcd instances and the database replication.

To do this, using AI to save time, we will create a function called "etcdctl" to allow interaction with etcd by sending commands to the associated pods (via crictl). It's worth knowing that etcdctl exists as an installable binary on the server, but we can avoid using it thanks to this trick (thank you, AI).

EID=$(sudo /usr/local/bin/crictl ps --name etcd --state Running -q | head -1)
etcdctl() {
  sudo /usr/local/bin/crictl exec "$EID" etcdctl \
    --endpoints=https://127.0.0.1:2379 \
    --cacert=/etc/kubernetes/pki/etcd/ca.crt \
    --cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt \
    --key=/etc/kubernetes/pki/etcd/healthcheck-client.key \
    "$@"
}
Declaration of the shell function etcdctl that executes etcdctl within the etcd container via crictl exec

Click the image to enlarge.

If etcdctl does not exist on the server (see my note above), it is present in the container that runs etcd. We will now enter the context of this container and then pass arguments to the etcdctl command located within it: the connection endpoint (127.0.0.1:2379 (normal, as it is the container itself, running etcd)) and the authentication elements, which are simply the key and certificate generated during the deployment of etcd.

We can now list the members

etcdctl member list -w table
etcdctl member list: The three etcd members are started with their peer addresses 2380 and client address 2379

Click the image to enlarge.

We can also see the overall status of the cluster

etcdctl endpoint health --cluster -w table
etcdctl endpoint health --cluster: All three etcd endpoints are healthy

Click the image to enlarge.

etcdctl endpoint status --cluster -w table
etcdctl endpoint status --cluster: prdk8sgru501 (192.168.10.161) is the etcd leader

Click the image to enlarge.

Leader and quorum

Interestingly, this output shows that among the servers participating in the cluster, at least according to etcd's definition, only one is currently the "leader", which is prdk8sgru501. The others are simply replicating the content. However, at the time of this command, the version of the database present on prdk8sgru501 serves as the reference and is being manipulated for writing. If this server were to fail, and its pod were stopped, the remaining servers would enter an election state to determine which one will take over… because they are still in sufficient numbers to "elect" a new leader… You now understand why you need at least three nodes… it's the principle of the RAFT protocol associated with etcd that requires always having a sufficient quorum of nodes to hold an election. With only two nodes, if you lose one, the remaining node cannot decide on its own to take over and needs the voice of another to agree on what to do… and that's normal… Imagine you have two nodes, but the leader becomes isolated from a network perspective. Each continues to run, but can no longer communicate with its neighbor. How can the surviving node decide that it can now record and follow changes? Perhaps it is the one that is isolated? This is a split-brain scenario. Now, if this latter node can communicate with a third node that confirms that it also cannot see the leader, then they can agree for one of them to take over.

This is a simplified explanation, but it shows you that choosing the number of these control plane nodes and their location in an architecture is not trivial. This is also why managed clusters offered by some cloud providers are interesting… because, in this case, it's no longer your problem; the control plane is handled by the provider.

Cilium

Let's continue now with Cilium, our CNI.

As you may have already noticed, we've seen quite a few Cilium pods in the kube-system namespace. The fact that the nodes appear as "Ready" and that the core DNS pods are active are good indicators that the CNI is set up correctly. The internal network is working because, without it, these elements wouldn't appear this way.

However, let's make sure Cilium is healthy. To do this, remember that in the xkub_cilium role, we deployed the CLI.

Let's use it:

sudo /usr/local/bin/cilium status --wait --kubeconfig /etc/kubernetes/admin.conf

Here, we can't rely on the config file used by kubectl (since we need to be in sudo), but we directly specify the admin.conf file located in /etc/kubernetes/, which is the original version of the config file present in our Ansible account profile. Remember that in the xkub_kubeadm_init role, this is the last step: copy admin.conf as config to the local user's .kube directory.

The output of the command shows that everything is green regarding Cilium.

Output of cilium status: Cilium, Operator, Envoy DaemonSet, and Hubble Relay are all OK; Helm chart version 1.20.4

Click the image to enlarge.

For those who want to go further, there's also this command:

sudo /usr/local/bin/cilium connectivity test --kubeconfig /etc/kubernetes/admin.conf

This will trigger a series of tests that can take quite a long time (several hours) during which pods will be executed to test different levels of connectivity and features specific to Cilium.

Starting the cilium connectivity test: Deploying test namespaces and pods

Click the image to enlarge.

Execution of the cilium connectivity test: pod-to-host, host-to-pod, and pod-to-cidr scenarios

Click the image to enlarge.

This is the final test to verify that everything is working correctly, including the firewall ports firewalld between the nodes. However, it's not uncommon for tests to fail at the end of execution, and this doesn't necessarily mean there's a problem. Some tests are simply not appropriate for the current configuration. Therefore, you should be careful when interpreting the results of these tests.

Cilium connectivity tests failed; interpret with caution

Click the image to enlarge.

Don't forget to clean up the pods after the tests are finished by deleting the associated namespaces.

kubectl delete namespace cilium-test-1 cilium-test-ccnp1 cilium-test-ccnp2 --ignore-not-found
Deleting the test namespaces cilium-test-1, cilium-test-ccnp1, and cilium-test-ccnp2

Click the image to enlarge.

Access to the API and kube-vip

Finally, one last thing: test access to the API from outside, and therefore also kube-vip.

First, let's verify that the kube-vip pods are in place.

kubectl get pod -n kube-system  -o wide| grep vip
One kube-vip pod per control plane, in a Running state

Click the image to enlarge.

Then, from my workstation, simple curl commands in WSL are enough to reassure us on this point, since by using the VIP IP address, I can successfully access the API

curl -sk https://192.168.10.121:6443/livez ; echo
curl -sk https://xkub.coolcorp.priv:6443/livez ; echo
curl calls to /livez of the API via the VIP IP address 192.168.10.121 and via xkub.coolcorp.priv: response is ok

Click the image to enlarge.

At this stage, I can't ask it anything, since I don't have a config file on my machine, but that is already enough to validate that the API is exposed.

By the way, if you are curious, by simply pinging the VIP and then using the command arp -a to list the MAC address associated with the IP, you can easily identify that it is currently the server prdk8sgru501 that has this IP.

Pinging the VIP 192.168.10.121, then arp -a: The VIP shares the MAC address of prdk8sgru501 (192.168.10.161).

Click the image to enlarge.

MAC address of the prdk8sgru501 VM in Xen Orchestra, which is identical to the one used by the VIP

Click the image to enlarge.

Conclusion

We have now reached the end of this intermediate step. At this point, our cluster is in place and ready to be used for what comes next. Its basic components are in place, and the network is active.

Despite using Ansible to automate everything, with AI assistance, it is important to understand what has been done and to have in mind the underlying mechanisms that were used to achieve this result.

We can now proceed to add third-party components to offer more services to our containerized applications. To do this, you will need to wait for the next articles.