Skip to main content

Avec Cilium

Cette documentation ne peut être exécutée uniquement sur un cluster ayant pour réseau Cilium.

 

Déclaration de la pool possible d'IP VIP :

cat <<EOF | kubectl apply -f -
apiVersion: cilium.io/v2alpha1
kind: CiliumLoadBalancerIPPool
metadata:
  name: worker-vip-pool
spec:
  blocks:
    - start: "192.168.1.2"
      stop:  "192.168.1.9"
  serviceSelector:
    matchLabels:
      expose: "true"
EOF

Déclaration de la mise en réseau : 

cat <<EOF | kubectl apply -f -
apiVersion: cilium.io/v2alpha1
kind: CiliumL2AnnouncementPolicy
metadata:
  name: worker-l2-policy
  namespace: kube-system
spec:
  nodeSelector:
    matchLabels:
      node-role.kubernetes.io/worker: "true"
  serviceSelector:
    matchLabels:
      expose: "true"
  loadBalancerIPs: true
  externalIPs: false
  interfaces:
    - ens18
EOF

Exemple de déploiement et de service permetant d'exposer un pod web via une VIP : 

cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
        - name: hello
          image: hashicorp/http-echo:latest
          args:
            - "-text=Hello from Cilium VIP 👋"
            - "-listen=:8080"
          ports:
            - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: hello-world
  namespace: default
  labels:
    expose: "true"
  annotations:
    lbipam.cilium.io/ips: "192.168.1.2"   # IP fixe dans le pool
spec:
  type: LoadBalancer
  selector:
    app: hello-world
  ports:
    - port: 80
      targetPort: 8080
EOF

Résultat :

image.png