Skip to content

Commit 7a3b2ac

Browse files
authored
Mainline Cilium support for Kubespray (#454)
Signed-off-by: Rareș Cosma <[email protected]>
1 parent 6788ef3 commit 7a3b2ac

File tree

6 files changed

+176
-2
lines changed

6 files changed

+176
-2
lines changed

bin/apply.bash

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ if [ -z "${CK8S_KUBESPRAY_NO_VENV+x}" ]; then
3232
fi
3333

3434
log_info "Running kubespray"
35-
ansible-playbook -i "${config[inventory_file]}" -i "${here}/node-labels-and-taints-inventory.bash" cluster.yml -b "${@}"
35+
ansible-playbook \
36+
-i "${config[inventory_file]}" \
37+
-i "${here}/node-labels-and-taints-inventory.bash" \
38+
-i "${here}/../dynamic-config/cilium-values-inventory.yaml" \
39+
cluster.yml -b "${@}"
3640

3741
log_info "Kubespray done"
3842

bin/run-playbook.bash

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ if [ -z "${CK8S_KUBESPRAY_NO_VENV+x}" ]; then
3434
fi
3535

3636
log_info "Running kubespray"
37-
ansible-playbook -i "${config[inventory_file]}" -i "${here}/node-labels-and-taints-inventory.bash" "-e serial=1" "playbooks/${playbook}" "${@}"
37+
ansible-playbook \
38+
-i "${config[inventory_file]}" \
39+
-i "${here}/node-labels-and-taints-inventory.bash" \
40+
-i "${here}/../dynamic-config/cilium-values-inventory.yaml" \
41+
"-e serial=1" "playbooks/${playbook}" "${@}"
3842

3943
popd
4044

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
ck8s_cilium:
2+
# policyEnforcementMode: Determine whether an endpoint accepts traffic from a source or not
3+
#
4+
# Has three options:
5+
# - default: endpoints have unrestricted network access until selected by policy
6+
# - always: policy enforcement is enabled on all endpoints even if no rules select specific endpoints.
7+
# - never: All traffic is allowed from any source (on ingress) or destination (on egress)
8+
policyEnforcementMode: default
9+
10+
# policyAuditMode: when true, no network policy is enforced.
11+
#
12+
# This feature helps to validate the impact of host policies before enforcing them.
13+
policyAuditMode: false
14+
15+
# enableNodeSelectability: when true, allows Kubernetes nodes to be selected
16+
# by cidr block selectors in classic NetworkPolicies.
17+
#
18+
# Without this, access to the Kubernets API Server pods might be restricted.
19+
#
20+
# See: https://github.com/cilium/cilium/issues/20550
21+
enableNodeSelectability: true
22+
23+
operator:
24+
unmanagedPodWatcher:
25+
restart: true
26+
monitoring:
27+
enabled: true
28+
installServiceMonitor: false
29+
30+
wireguard:
31+
enabled: true
32+
strictMode: false
33+
34+
hubble:
35+
enabled: true
36+
monitoring:
37+
installServiceMonitor: false
38+
metrics:
39+
- drop:labelsContext=traffic_direction,source_pod,source_namespace,source_ip,destination_pod,destination_namespace,destination_ip
40+
- flow:labelsContext=traffic_direction,source_pod,source_namespace,source_ip,destination_pod,destination_namespace,destination_ip
41+
- dns
42+
- tcp
43+
- icmp
44+
- httpV2
45+
46+
prometheus:
47+
enabled: true
48+
installServiceMonitor: false
49+
50+
envoy:
51+
enabled: false

docs/cilium.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Cilium as network plugin
2+
3+
## Creating a Cilium cluster
4+
5+
To create a new cluster that uses `cilium` as its network plugin, set the following keys in `group_vars/all/k8s_cluster/ck8s-k8s-cluster.yaml`:
6+
7+
```yaml
8+
# Set cilium as the network plugin
9+
kube_network_plugin: cilium
10+
11+
# Pin the cilium chart version
12+
cilium_version: "1.17.5"
13+
14+
# Tell cilium to store identities in CRDs rather than try talking to etcd directly
15+
cilium_identity_allocation_mode: "crd"
16+
17+
# Enable hubble (needed for some of the metrics)
18+
cilium_enable_hubble: true
19+
cilium_hubble_install: true
20+
cilium_hubble_tls_generate: true
21+
22+
# See https://github.com/kubernetes-sigs/kubespray/issues/12276
23+
kube_owner: root
24+
```
25+
26+
## Configuring Cilium
27+
28+
Cilium configuration itself lives in `group_vars/all/k8s_cluster/ck8s-cilium.yaml`.
29+
30+
It closely mimics the [Cilium configuration block that from CAPI](https://github.com/elastisys/ck8s-cluster-api/blob/e2ce0c947c773efa1e1b8e78fcdc2c1f50f484d5/config/base-values.yaml#L119-L156).
31+
32+
For new clusters the file should be copied automatically to the configuration directory during the `init` step.
33+
34+
We don't yet have a migration plan for existing clusters to switch CNIs, but should you desire to experiment you'll need to copy the file manually.
35+
36+
## Development tips
37+
38+
After a successful initial run of Kubespray, if you just want to test out configuration changes you can speed up subsequent runs by a huge factor by skipping certain tags:
39+
40+
./bin/ck8s-kubespray apply sc --skip-tags "bootstrap-os,preinstall,container-engine,download,node"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
all:
2+
vars:
3+
cilium_extra_values: "{{ cilium_extra_values_template | from_yaml }}"
4+
cilium_extra_values_template: |
5+
{% if ck8s_cilium | default(false) %}
6+
policyEnforcementMode: {{ ck8s_cilium.policyEnforcementMode }}
7+
8+
policyAuditMode: {{ ck8s_cilium.policyAuditMode }}
9+
10+
operator:
11+
unmanagedPodWatcher:
12+
restart: {{ ck8s_cilium.operator.unmanagedPodWatcher.restart }}
13+
prometheus:
14+
enabled: {{ ck8s_cilium.operator.monitoring.enabled }}
15+
serviceMonitor:
16+
enabled: {{ ck8s_cilium.operator.monitoring.installServiceMonitor }}
17+
18+
encryption:
19+
enabled: {{ ck8s_cilium.wireguard.enabled }}
20+
type: wireguard
21+
strictMode:
22+
enabled: {{ ck8s_cilium.wireguard.strictMode }}
23+
24+
hubble:
25+
enabled: {{ ck8s_cilium.hubble.enabled }}
26+
metrics:
27+
enabled: {{ ck8s_cilium.hubble.metrics }}
28+
serviceMonitor:
29+
enabled: {{ ck8s_cilium.hubble.monitoring.installServiceMonitor }}
30+
31+
prometheus:
32+
enabled: {{ ck8s_cilium.prometheus.enabled }}
33+
serviceMonitor:
34+
enabled: {{ ck8s_cilium.prometheus.installServiceMonitor }}
35+
trustCRDsExist: true
36+
37+
envoy:
38+
enabled: {{ ck8s_cilium.envoy.enabled }}
39+
40+
{% if ck8s_cilium.enableNodeSelectability | default(false) %}
41+
policyCIDRMatchMode: nodes
42+
{% endif %}
43+
44+
annotateK8sNode: true
45+
46+
{% else %}
47+
{}
48+
{% endif %}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
HERE="$(dirname "$(readlink -f "${0}")")"
4+
ROOT="$(readlink -f "${HERE}/../../../")"
5+
6+
# shellcheck source=scripts/migration/lib.sh
7+
source "${ROOT}/scripts/migration/lib.sh"
8+
9+
cilium_path="group_vars/k8s_cluster/ck8s-cilium.yaml"
10+
11+
src_file="${ROOT}/config/common/${cilium_path}"
12+
13+
if [[ "${CK8S_CLUSTER}" =~ ^(sc|both)$ ]]; then
14+
dest_file="${CK8S_CONFIG_PATH}/sc-config/${cilium_path}"
15+
if [[ ! -f "${dest_file}" ]]; then
16+
log_info "Copying ck8s-cilium config to SC [src=${src_file} dest=${dest_file}]"
17+
cp "${src_file}" "${dest_file}"
18+
fi
19+
fi
20+
21+
if [[ "${CK8S_CLUSTER}" =~ ^(wc|both)$ ]]; then
22+
dest_file="${CK8S_CONFIG_PATH}/wc-config/${cilium_path}"
23+
if [[ ! -f "${dest_file}" ]]; then
24+
log_info "Copying ck8s-cilium config to WC [src=${src_file} dest=${dest_file}]"
25+
cp "${src_file}" "${dest_file}"
26+
fi
27+
fi

0 commit comments

Comments
 (0)