Step 9: The network under Kubernetes and the Cilium CNI
- Without a CNI, nothing is accessible: Kubernetes network principles (Pod-to-Pod, CIDRs, CoreDNS).
- Choice of Cilium and eBPF.
- Deployment via Helm with the xkub_cilium role, replacing kube-proxy, Hubble.
- Idempotent role; appendix of commands outside Ansible.
Introduction
It's time to address the last role present within the playbook xkub_30_cluster.yml, which is the xkub_cilium role
Previously, we saw how to handle cluster initialization via the xkub_kubeadm_init role and then how to add all the nodes with the xkub_kubeadm_join role. This involved using kubeadm, which Ansible can execute to run the necessary commands on each server.
If the playbook ended like this, we would have an operational cluster in the fundamental sense, with the control plane and worker nodes deployed according to our target architecture.
The basic components, such as the API server or the ETCD database, would be in place.
However, it wouldn't be possible to run an application on the cluster, or at least not make it accessible.
The reason is that the network layer simply wouldn't be present, and that is precisely the purpose of this xkub_cilium role, which we will examine in this article.
The network under K8S
Before delving into the details of the role, let's take a moment to discuss some principles related to networking within Kubernetes.
First, it is important to note that the network architecture of Kubernetes abandons the traditional model of ports mapped on the host, such as bridges with systematic NAT (at least by default). There's no Docker bridge here, and instead, we operate on the principle of a flat network where the Pod is the atomic unit of addressing.
Kubernetes does not implement the network itself; it imposes a strict method that any underlying infrastructure must adhere to.
- Pod-to-Pod without NAT: Each Pod receives its own unique IP address within the cluster (PodCIDR). All Pods can communicate with each other directly, whether they are on the same node or on different nodes, without address translation (NAT).
- Node-to-Pod without NAT: System daemons on a node (such as the kubelet for livenessProbe / readinessProbe probes) can communicate with any Pod without NAT.
- Consistent IP perception: The IP address that a Pod sees for itself is exactly the same as the one seen by other Pods and nodes when it sends traffic to them.
- Network Namespace (NetNS) sharing by Pod: Within the same Pod, all containers share the same Linux network stack (interfaces, routing tables, iptables rules) and communicate with each other via localhost (127.0.0.1).
In addition to these rules, there are three IP address ranges (CIDRs).
- Node Network: This is the physical or virtual network associated with the cluster server. This is the actual IP address of the nodes, which we configured in the VM deployment using Terraform. We will therefore find the 192.168.10.0 network for the LAN nodes and the 192.168.5.0 network for the DMZ nodes.
- Pod Network (--cluster-cidr): These are the IP addresses dynamically assigned to Pods. In our architecture, we chose 10.11.0.0/16. Each pod running on the cluster will have an IP address in this range. It is therefore important to choose a wide range, since the number of pods can grow very quickly, and also a range that is not already routed on your existing network.
- Service Network (--service-cluster-ip-range): These are the virtual IP addresses (VIP / ClusterIP) that do not exist on any physical or virtual network interface, but serve as load balancing targets for Pods. Therefore, a pod is not intended to be directly accessed by its IP address, which is taken from the previous range, but rather to be exposed by a service that will redirect traffic to one of the covered pods. In our case, we have chosen 10.12.0.0/16 for the services. Again, the range must be wide and not routed.
It is important to be aware that internally, and by default, regardless of the namespaces used, everyone communicates with everyone else, but not necessarily with the outside world.
Internal DNS resolution
Furthermore, we also have a complete internal DNS resolution mechanism with DNS servers running among the core components. In a Vanilla installation, CoreDNS is present and deployed at the same time as the cluster is initialized.
So there is an internal cluster domain, set by default to cluster.local, and a service inside the cluster can always be resolved in the form "whoami.default.svc.cluster.local". For names outside the cluster, DNS requests are forwarded to the DNS servers configured on the nodes.
Here is a diagram that explains the principle of internal resolution for a K8S cluster.
Click the image to enlarge.
The CNI
However, this entire network architecture is not functional without adding a CNI (Container Network Interface) plugin to the cluster.
This plugin is responsible for interacting with the container runtime (containerd) for network management.
It creates pairs of virtual interfaces associated with pods, allocates IPs from the configured ranges, and routes traffic between nodes.
This routing is possible using two options:
- Overlay Mode (Encapsulation): The CNI encapsulates the Pod-to-Pod packet within a UDP packet on the node network via VXLAN or Geneve. It's simple to deploy (no dependency on the underlying physical L2/L3 network), but it adds a slight CPU overhead and reduces the MTU (typically from 1500 to 1450 bytes).
- Native Routing Mode (Direct Routing / BGP): No encapsulation. Nodes exchange PodCIDR routes (often via BGP or cloud routing tables) and route packets at wire speed with the native MTU.
This choice, and others, are specific to the chosen plugin. Traditional CNIs like Flannel or Calico (in standard mode) rely on the legacy Linux kernel stack (netfilter/iptables) and kube-proxy, the native K8S component for exposing services.
The problem is that at a large scale, iptables can become a bottleneck, where each associated rule must be evaluated sequentially.
Cilium
That's why other plugins, like the one we chose, Cilium, prefer to rely on eBPF (Extended Berkeley Packet Filter). This protocol allows direct interaction within the Linux kernel space without having to modify the kernel or load modules. This enables observing, deciding, or modifying anything related to the network.
In our architecture, Cilium will rely on eBPF for:
- pod routing: directing traffic between pods on different nodes, encapsulated in VXLAN (so we are in overlay mode).
- Services: it replaces kube-proxy and iptables (ClusterIP addresses in 10.12.0.0/16 are resolved by eBPF) (that's why, during cluster initialization, we removed the deployment of kube-proxy);
- NetworkPolicies: it filters traffic based on pod identity rather than IP address. This will allow us to integrate firewall rules that are much more advanced than the simple network policy allowed by K8S by default.
- observability: Hubble, the monitoring component associated with Cilium, reads what eBPF sees to provide visibility into network flows. This point is very interesting because, in architectures like microservices, which are common in K8S architectures, observability of flows becomes necessary to identify bottlenecks and ensure good security for the entire system.
eBPF makes the Linux kernel programmable in a safe and fast way. Cilium uses a more efficient and visible network logic to replace iptables and kube-proxy.
The Cilium project started in 2015, driven by Thomas Graf, a historical Linux kernel developer at RedHat.
Gradually, it gained popularity and became the default engine for Kubernetes solutions operated by major cloud providers (Google, AWS, Azure) in 2020, and joined the CNCF (Cloud Native Computing Foundation) in 2021.
In December 2023, Cisco acquired Isovalent, the company that was created as a result of the project, to make Cilium the foundation of its security and cloud-native strategy, while maintaining the open governance of the project under the auspices of the CNCF. (There is a paid version of Cilium that allows you to subscribe to support and obtain additional features, but the core of the project and its components remain open source).
Today, we can say that Cilium has become the most deployed CNI plugin, which does not necessarily mean that it is always the best choice. Calico, for example, remains widely used and is known for being more performant.
Everything will depend on your needs and the specific network requirements of your architectures.
For this cookbook, I chose Cilium because it seemed the most appropriate and representative of what you might find in a new K8S architecture today.
Click the image to enlarge.
The xkub_cilium role
Now, let's explore the role responsible for deploying Cilium on our cluster.
This role, integrated into the playbook xkub_30_cluster.yml, will only be activated on the first node of the cluster. It is unnecessary to connect to the other nodes, as all configuration will pass through the K8S API.
- name: Cilium — CNI avec kubeProxyReplacement (chart Helm depuis le control plane primaire)
hosts: "{{ groups['k8s_controlplane_lan'] | sort | first }}"
become: true
roles:
- xkub_cilium
playbooks/xkub_30_cluster.yml (excerpt)
As usual, we'll explore the role's directory structure to process each file
Click the image to enlarge.
Role variables
In the Defaults folder and the main.yml file, we find the variables specific to the role.
---
xkub_cilium_kube_proxy_replacement: true
xkub_cilium_hubble_enabled: true
xkub_cilium_helm_repo_url: https://helm.cilium.io/
xkub_cilium_release_name: cilium
xkub_cilium_release_namespace: kube-system
xkub_cilium_values_path: /etc/kubernetes/cilium-values.yaml
xkub_cilium_helm_wait_timeout: 10m
roles/xkub_cilium/defaults/main.yml
These variables are mainly used to specify where to get Cilium and how to install it.
Helm
To do this, we'll use Helm, which is the package manager available for Kubernetes. While K8S objects are typically deployed as YAML files specific to each object, Helm allows you to hide the complexity of these objects by providing access to repositories containing what are called Charts. These are structured archives or folders that contain all the Kubernetes manifest templates needed to run an application.
If a default configuration is provided, it can be overridden to customize the installation, and this is the role of the /etc/kubernetes/cilium-values.yaml file, defined by the xkub_cilium_values_path variable
Note that we will deploy Cilium in the default namespace kube-system, which is the namespace grouping the basic components of the cluster and, theoretically, accessible only to cluster administrators.
It is possible to dedicate a namespace to Cilium; it's a matter of preference and personal logic.
Tasks
We can now look at the tasks folder.
main.yml
The main.yml file only references the order in which the tasks are executed.
---
- name: Installer Helm (binaire officiel, version épinglée)
ansible.builtin.import_tasks: 01_helm.yml
tags:
- xkub
- xkub.cilium
- xkub.cilium.helm
- name: Installer cilium-cli (vérification post-déploiement uniquement)
ansible.builtin.import_tasks: 02_cilium_cli.yml
tags:
- xkub
- xkub.cilium
- xkub.cilium.cli
- name: Déployer le chart Helm Cilium
ansible.builtin.import_tasks: 03_deploy.yml
tags:
- xkub
- xkub.cilium
- xkub.cilium.deploy
roles/xkub_cilium/tasks/main.yml
01_helm.yml
The deployment of Cilium by Ansible starts with the actions described in 01_helm.yml
---
# Helm est installé depuis le binaire officiel (version épinglée dans
# versions.yml). Comme containerd/crictl, il échappe à dnf : la garde doit
# porter sur la VERSION et non sur la présence du fichier, sinon une montée de
# version (ou un correctif de CVE) ne s'applique jamais
- name: Relever la version de Helm installée
ansible.builtin.command:
cmd: "{{ k8s_helm_binary_path }} version --short"
register: xkub_cilium_helm_installed
changed_when: false
failed_when: false
# `helm version --short` renvoie « v3.22.1+g<sha> ».
# Absent ou illisible => chaîne vide => la version cible est (ré)installée.
- name: Extraire le numéro de version de Helm
ansible.builtin.set_fact:
xkub_cilium_helm_current: >-
{{ (xkub_cilium_helm_installed.stdout
| regex_search('v(\d+\.\d+\.\d+)', '\1')
| default([''], true) | first) | default('', true) }}
# Intégrité : get_url vérifie la somme SHA256 épinglée dans versions.yml AVANT
# toute extraction ; une archive altérée ou une version changée sans sa somme
# fait échouer la tâche au lieu d'installer un binaire non vérifié.
- name: Télécharger l'archive Helm {{ helm_version }} (somme SHA256 vérifiée)
ansible.builtin.get_url:
url: "{{ helm_download_url }}"
dest: /tmp/helm-v{{ helm_version }}-linux-amd64.tar.gz
checksum: "sha256:{{ helm_sha256 }}"
owner: root
group: root
mode: "0600"
when: xkub_cilium_helm_current != helm_version
- name: Extraire l'archive Helm {{ helm_version }} dans /tmp
ansible.builtin.unarchive:
src: /tmp/helm-v{{ helm_version }}-linux-amd64.tar.gz
dest: /tmp
remote_src: true
when: xkub_cilium_helm_current != helm_version
- name: Installer le binaire Helm dans {{ k8s_helm_binary_path }}
ansible.builtin.copy:
src: /tmp/linux-amd64/helm
dest: "{{ k8s_helm_binary_path }}"
owner: root
group: root
mode: "0755"
remote_src: true
when: xkub_cilium_helm_current != helm_version
- name: Nettoyer l'archive Helm et son extraction
ansible.builtin.file:
path: "{{ item }}"
state: absent
loop:
- /tmp/linux-amd64
- /tmp/helm-v{{ helm_version }}-linux-amd64.tar.gz
when: xkub_cilium_helm_current != helm_version
# Sans ce plugin, kubernetes.core.helm avertit « The default idempotency check
# can fail to report changes in certain cases » et rapporte volontiers
# `changed` à chaque exécution, même quand la release est identique
- name: Installer le plugin helm-diff ({{ helm_diff_version }})
kubernetes.core.helm_plugin:
binary_path: "{{ k8s_helm_binary_path }}"
plugin_path: https://github.com/databus23/helm-diff
plugin_version: "{{ helm_diff_version }}"
state: present
roles/xkub_cilium/tasks/01_helm.yml
As explained above, Helm was chosen to install Cilium. It is possible to use other methods, but Helm is the most common.
To do this, we first check if the Helm binary is already present. If not, we will retrieve it directly from the official website using the helm_download_url variable, verifying the integrity of the downloaded archive against the SHA256 checksum declared in helm_sha256 before extracting it. These variables are not defined at the role level, but in the variable file versions.yml located in .\inventory\group_vars\clu_k8s_xkub, as with other variables used here (feel free to review the principle of Ansible variables).
# Helm ( binaire officiel).
helm_version: "3.22.1"
helm_download_url: "https://get.helm.sh/helm-v{{ helm_version }}-linux-amd64.tar.gz"
# Somme SHA256 de l'archive, vérifiée AVANT extraction.
helm_sha256: "896cf63684a42a723d61c980369d6e588330927deb13676ca0d85006dd6da0ea"
# Plugin helm-diff — requis par kubernetes.core.helm pour une détection de
# changement fiable. Sans lui, le module avertit « The default idempotency
# check can fail to report changes in certain cases » et rapporte volontiers
# `changed` à chaque exécution
helm_diff_version: "3.15.15"
cilium_version: "1.20.4"
cilium_cli_version: "0.20.3"
kube_vip_version: "1.3.1"
# cilium-cli — binaire officiel GitHub, sert UNIQUEMENT à la vérification
# post-déploiement (cilium status, cilium connectivity test) : Cilium
cilium_cli_download_url: "https://github.com/cilium/cilium-cli/releases/download/v{{ cilium_cli_version }}/cilium-linux-amd64.tar.gz"
cilium_cli_sha256: "b987ad0d195310d3fc96553aa7bcd41d1e97b64713ecdfee3eb48dd27e1ec7d7"
inventory/group_vars/clu_k8s_xkub/versions.yml (excerpt)
Helm is then placed in the folder corresponding to the k8s_helm_binary_path variable
# --- Outillage installé hors gestionnaire de paquets -------------------------
k8s_helm_binary_path: /usr/local/bin/helm
inventory/group_vars/clu_k8s_xkub/main.yml (excerpt)
In addition to Helm, we also deploy helm-diff. This tool, similar to a terraform plan, allows you to see what would change in the cluster before applying an update via Helm.
This allows Ansible to identify whether changes are needed or not, and ensures the idempotence of our playbook; otherwise, it would redeploy Cilium every time it runs.
02_cilium_cli.yml
We can now move on to the 02_cilium_cli.yml file
---
# cilium-cli sert EXCLUSIVEMENT à la vérification (cilium status, cilium
- name: Relever la version de cilium-cli installée
ansible.builtin.command:
cmd: /usr/local/bin/cilium version --client
register: xkub_cilium_cli_installed
changed_when: false
failed_when: false
- name: Extraire le numéro de version de cilium-cli
ansible.builtin.set_fact:
xkub_cilium_cli_current: >-
{{ (xkub_cilium_cli_installed.stdout
| regex_search('v(\d+\.\d+\.\d+)', '\1')
| default([''], true) | first) | default('', true) }}
- name: Télécharger l'archive cilium-cli {{ cilium_cli_version }} (somme SHA256 vérifiée)
ansible.builtin.get_url:
url: "{{ cilium_cli_download_url }}"
dest: /tmp/cilium-cli-v{{ cilium_cli_version }}-linux-amd64.tar.gz
checksum: "sha256:{{ cilium_cli_sha256 }}"
owner: root
group: root
mode: "0600"
when: xkub_cilium_cli_current != cilium_cli_version
- name: Extraire l'archive cilium-cli {{ cilium_cli_version }} dans /usr/local/bin
ansible.builtin.unarchive:
src: /tmp/cilium-cli-v{{ cilium_cli_version }}-linux-amd64.tar.gz
dest: /usr/local/bin
remote_src: true
when: xkub_cilium_cli_current != cilium_cli_version
- name: Supprimer l'archive cilium-cli {{ cilium_cli_version }} téléchargée
ansible.builtin.file:
path: /tmp/cilium-cli-v{{ cilium_cli_version }}-linux-amd64.tar.gz
state: absent
when: xkub_cilium_cli_current != cilium_cli_version
roles/xkub_cilium/tasks/02_cilium_cli.yml
As I mentioned earlier, Cilium is a very advanced CNI plugin. It offers many features, and to simplify its management and administration, it is possible to download a binary that provides a CLI for interacting with it.
This section of the role aims to simply retrieve the CLI and install it in /usr/local/bin, ensuring that we use the CLI version that corresponds to our target Cilium version, which we will discuss shortly. As with Helm, the archive is verified by its SHA256 checksum (cilium_cli_sha256) before being extracted and then deleted.
03_deploy.yml
The last task file is 03_deploy.yml
---
- name: Déployer les values Helm Cilium
ansible.builtin.template:
src: cilium-values.yaml.j2
dest: "{{ xkub_cilium_values_path }}"
owner: root
group: root
mode: "0644"
- name: "Installer/mettre à jour le chart Helm Cilium ({{ cilium_version }})"
kubernetes.core.helm:
binary_path: "{{ k8s_helm_binary_path }}"
name: "{{ xkub_cilium_release_name }}"
chart_ref: cilium
chart_repo_url: "{{ xkub_cilium_helm_repo_url }}"
chart_version: "{{ cilium_version }}"
release_namespace: "{{ xkub_cilium_release_namespace }}"
kubeconfig: /etc/kubernetes/admin.conf
values_files:
- "{{ xkub_cilium_values_path }}"
wait: true
wait_timeout: "{{ xkub_cilium_helm_wait_timeout }}"
roles/xkub_cilium/tasks/03_deploy.yml
This will cover the actual deployment process.
To do this, we first copy the configuration file template that will allow us to customize the installation of Helm on the cluster. We will see more about this later.
Next, Ansible runs the helm command, which would be the following if we had to type it by hand
helm upgrade --install cilium cilium \
--repo https://helm.cilium.io/ \
--version 1.20.4 \
--namespace kube-system \
--kubeconfig /etc/kubernetes/admin.conf \
-f /etc/kubernetes/cilium-values.yaml \
--wait --timeout 10m
This action will integrate the Cilium repository into the Helm configuration, retrieve the chart associated with the desired version, and then use our configuration file, along with the administrator's configuration file for our cluster, to deploy Cilium according to our specifications.
Templates
cilium-values.yaml.j2
This allows us to proceed to the templates directory and focus on the cilium-values.yaml.j2 file that is present.
# {{ ansible_managed }}
# Values Helm Cilium — version épinglée dans group_vars/clu_k8s_xkub/versions.yml
kubeProxyReplacement: {{ xkub_cilium_kube_proxy_replacement | bool | lower }}
k8sServiceHost: {{ k8s_api_vip }}
k8sServicePort: {{ k8s_api_port }}
ipam:
mode: cluster-pool
operator:
clusterPoolIPv4PodCIDRList:
- "{{ k8s_pod_cidr }}"
hubble:
relay:
enabled: {{ xkub_cilium_hubble_enabled | bool | lower }}
ui:
enabled: {{ xkub_cilium_hubble_enabled | bool | lower }}
frontend:
server:
ipv6:
enabled: false
tls:
auto:
enabled: true
method: helm
certValidityDuration: 1095
roles/xkub_cilium/templates/cilium-values.yaml.j2
Once copied to the first node of the cluster, this is what it will look like
# Ansible managed
kubeProxyReplacement: true
k8sServiceHost: 192.168.10.121
k8sServicePort: 6443
ipam:
mode: cluster-pool
operator:
clusterPoolIPv4PodCIDRList:
- "10.11.0.0/16"
hubble:
relay:
enabled: true
ui:
enabled: true
frontend:
server:
ipv6:
enabled: false
tls:
auto:
enabled: true
method: helm
certValidityDuration: 1095
/etc/kubernetes/cilium-values.yaml
It allows us to specify the IP address of the VIP associated with the K8S API so that Cilium can communicate with the cluster (we are not using the DNS name to avoid dependencies on name resolution at this level). We specify that Cilium should replace kube-proxy, since we will not have deployed it (and we will thus use all of Cilium's capabilities).
In the IPAM section, we indicate that we are in cluster-pool mode, meaning that Cilium will be responsible for dividing the 10.11.0.0/16 range (our pod range) into subranges specific to each node.
The Hubble section allows us to enable network traffic observability, as mentioned earlier, which is an important capability to implement. Note that an internal certificate will be used for the components related to this feature; Helm will generate it with a validity of 3 years. It will be updated with each Cilium update.
Conclusion
We have finally reached the end of the xkub_30_cluster.yml playbook, presenting all the associated roles and ending with the xkub_cilium role responsible for deploying the Cilium CNI.
This has allowed us to see the main network principles in K8S that are important to know. It is a complete paradigm of which we must be aware. We are already starting to touch on one of the particularities of K8S, namely embedding all the logic specific to an application and not just the application itself. Everything related to the network access of the latter can be integrated into its deployment, and the choice of a CNI like Cilium is a key element in a Kubernetes architecture.
The next article will allow us to finally launch our playbook and verify whether everything that has been said so far is functional. This will be an opportunity to review the cluster configuration before proceeding further with its operation.
Summary of variables and equivalent commands outside of Ansible
This appendix summarizes all the variables used by Ansible in this article and provides an equivalent for the commands and configurations implemented by Ansible in this section.
Variables used
| Variable | Valeur | Déclarée dans |
|---|---|---|
helm_version |
3.22.1 |
inventory/group_vars/clu_k8s_xkub/versions.yml |
helm_download_url |
https://get.helm.sh/helm-v3.22.1-linux-amd64.tar.gz |
inventory/group_vars/clu_k8s_xkub/versions.yml |
helm_sha256 |
896cf63684a42a723d61c980369d6e588330927deb13676ca0d85006dd6da0ea |
inventory/group_vars/clu_k8s_xkub/versions.yml |
helm_diff_version |
3.15.15 |
inventory/group_vars/clu_k8s_xkub/versions.yml |
cilium_version |
1.20.4 (version du chart) |
inventory/group_vars/clu_k8s_xkub/versions.yml |
cilium_cli_version |
0.20.3 |
inventory/group_vars/clu_k8s_xkub/versions.yml |
cilium_cli_download_url |
https://github.com/cilium/cilium-cli/releases/download/v0.20.3/cilium-linux-amd64.tar.gz |
inventory/group_vars/clu_k8s_xkub/versions.yml |
cilium_cli_sha256 |
b987ad0d195310d3fc96553aa7bcd41d1e97b64713ecdfee3eb48dd27e1ec7d7 |
inventory/group_vars/clu_k8s_xkub/versions.yml |
k8s_helm_binary_path |
/usr/local/bin/helm |
inventory/group_vars/clu_k8s_xkub/main.yml |
k8s_api_vip |
192.168.10.121 (→ k8sServiceHost) |
inventory/group_vars/clu_k8s_xkub/main.yml |
k8s_api_port |
6443 (→ k8sServicePort) |
inventory/group_vars/clu_k8s_xkub/main.yml |
k8s_pod_cidr |
10.11.0.0/16 (→ clusterPoolIPv4PodCIDRList) |
inventory/group_vars/clu_k8s_xkub/main.yml |
xkub_cilium_kube_proxy_replacement |
true |
roles/xkub_cilium/defaults/main.yml |
xkub_cilium_hubble_enabled |
true |
roles/xkub_cilium/defaults/main.yml |
xkub_cilium_helm_repo_url |
https://helm.cilium.io/ |
roles/xkub_cilium/defaults/main.yml |
xkub_cilium_release_name |
cilium |
roles/xkub_cilium/defaults/main.yml |
xkub_cilium_release_namespace |
kube-system |
roles/xkub_cilium/defaults/main.yml |
xkub_cilium_values_path |
/etc/kubernetes/cilium-values.yaml |
roles/xkub_cilium/defaults/main.yml |
xkub_cilium_helm_wait_timeout |
10m |
roles/xkub_cilium/defaults/main.yml |
xkub_cilium_helm_installed / xkub_cilium_helm_current |
sortie de helm version --short / numéro extrait |
register et set_fact dans roles/xkub_cilium/tasks/01_helm.yml |
xkub_cilium_cli_installed / xkub_cilium_cli_current |
sortie de cilium version --client / numéro extrait |
register et set_fact dans roles/xkub_cilium/tasks/02_cilium_cli.yml |
ansible_user |
ansible-windows |
inventory/hosts.yml (all.vars) |
Equivalent without Ansible
Connexion : ssh [email protected], puis sudo -i. Toutes les commandes tournent en root, sur prdk8sgru501.
| # | Action | Serveur | Compte | Commande(s) |
|---|---|---|---|---|
| 1 | Relever la version de Helm installée (étapes 2 à 4 seulement si elle diffère de v3.22.1) |
prdk8sgru501 | root | /usr/local/bin/helm version --short |
| 2 | Télécharger Helm 3.22.1, vérifier sa somme SHA256 et l'extraire | prdk8sgru501 | root | curl -fsSL -o /tmp/helm-v3.22.1-linux-amd64.tar.gz https://get.helm.sh/helm-v3.22.1-linux-amd64.tar.gzecho "896cf63684a42a723d61c980369d6e588330927deb13676ca0d85006dd6da0ea /tmp/helm-v3.22.1-linux-amd64.tar.gz" | sha256sum -c -tar -C /tmp -xzf /tmp/helm-v3.22.1-linux-amd64.tar.gz |
| 3 | Installer le binaire | prdk8sgru501 | root | install -m 755 -o root -g root /tmp/linux-amd64/helm /usr/local/bin/helm |
| 4 | Nettoyer | prdk8sgru501 | root | rm -rf /tmp/linux-amd64 /tmp/helm-v3.22.1-linux-amd64.tar.gz |
| 5 | Plugin helm-diff 3.15.15 (s'il n'apparaît pas dans helm plugin list) |
prdk8sgru501 | root | helm plugin install https://github.com/databus23/helm-diff --version 3.15.15 |
| 6 | Relever la version de cilium-cli (étape 7 seulement si elle diffère de v0.20.3) |
prdk8sgru501 | root | /usr/local/bin/cilium version --client |
| 7 | Installer cilium-cli 0.20.3 après vérification de sa somme SHA256 | prdk8sgru501 | root | curl -fsSL -o /tmp/cilium-cli-v0.20.3-linux-amd64.tar.gz https://github.com/cilium/cilium-cli/releases/download/v0.20.3/cilium-linux-amd64.tar.gzecho "b987ad0d195310d3fc96553aa7bcd41d1e97b64713ecdfee3eb48dd27e1ec7d7 /tmp/cilium-cli-v0.20.3-linux-amd64.tar.gz" | sha256sum -c -tar -C /usr/local/bin -xzf /tmp/cilium-cli-v0.20.3-linux-amd64.tar.gzrm -f /tmp/cilium-cli-v0.20.3-linux-amd64.tar.gz |
| 8 | Écrire les values Helm | prdk8sgru501 | root | Créer /etc/kubernetes/cilium-values.yaml (bloc A), chmod 644 |
| 9 | (facultatif) Voir ce qu'un upgrade changerait | prdk8sgru501 | root | helm diff upgrade cilium cilium --repo https://helm.cilium.io/ --version 1.20.4 -n kube-system --kubeconfig /etc/kubernetes/admin.conf -f /etc/kubernetes/cilium-values.yaml |
| 10 | Installer ou mettre à jour Cilium | prdk8sgru501 | root | Bloc B |
| 11 | Vérifier | prdk8sgru501 | root | export KUBECONFIG=/etc/kubernetes/admin.confcilium status --waitkubectl get nodes (les nœuds passent Ready) |
L'étape 9 correspond à ce que fait Ansible en interne. Avec helm-diff installé, le module kubernetes.core.helm compare la release au chart et ne lance l'upgrade que s'il trouve une différence. C'est ce qui rend le rôle idempotent.
Bloc A /etc/kubernetes/cilium-values.yaml
kubeProxyReplacement: true
k8sServiceHost: 192.168.10.121
k8sServicePort: 6443
ipam:
mode: cluster-pool
operator:
clusterPoolIPv4PodCIDRList:
- "10.11.0.0/16"
hubble:
relay:
enabled: true
ui:
enabled: true
frontend:
server:
ipv6:
enabled: false
tls:
auto:
enabled: true
method: helm
certValidityDuration: 1095
Bloc B déploiement du chart
helm upgrade --install cilium cilium \
--repo https://helm.cilium.io/ \
--version 1.20.4 \
--namespace kube-system \
--kubeconfig /etc/kubernetes/admin.conf \
-f /etc/kubernetes/cilium-values.yaml \
--wait --timeout 10m