部署cilium环境和hubble可视化UI界面

官网:https://docs.cilium.io/en/v1.10/

Cilium+hubble

Cilium 是一个基于 eBPF 和 XDP 的高性能容器网络方案的开源项目,目标是为微服务环境提供网络、负载均衡、安全功能,主要定位是容器平台。

image.png

部署Cilium

!!!!!!!!!!!版本要求!!!!!!!!!!!

  1. Kubernetes >= 1.9
  2. Linux kernel >= 4.9
  3. ETCD >= 3.1.0
  4. kubernetes 环境中安装了 Helm 3
  5. Kubernetes in CNI mode
  6. 在所有 worker node 上挂载 BPF 文件系统
  7. //推荐:在 kube-controller-manager 上使能 PodCIDR allocation (--allocate-node-cidrs)

安装 helm 3

  1. wget https://get.helm.sh/helm-v3.1.2-linux-amd64.tar.gz
  2. tar -zxvf helm-v3.1.2-linux-amd64.tar.gz
  3. mv linux-amd64/helm /usr/local/bin/
  4. helm version #查看版本

挂载 BPF 文件系统

  1. mount bpffs /sys/fs/bpf -t bpf
  2. mount |grep bpf
  3. bpffs on /sys/fs/bpf type bpf (rw,relatime)
  4. echo "bpffs /sys/fs/bpf bpf defaults 0 0" >> /etc/fstab

kubernetes 配置

  1. # 在所有的 kubernetes node 中的 kubelet 配置使用 CNI 模式, kubelet.config 中添加
  2. --network-plugin=cni
  3. # 在 kube-controller-manager 中使能 PodCIDR, kube-controller-manager.config 中添加
  4. --allocate-node-cidrs=tru

部署 Cilium

添加仓库并安装
  1. helm repo add cilium https://helm.cilium.io/
  2. helm install cilium cilium/cilium --version 1.10.0 --namespace kube-system

验证安装
  1. curl -L --remote-name-all https://github.com/cilium/cilium-cli/releases/latest/download/cilium-linux-amd64.tar.gz{,.sha256sum}
  2. sha256sum --check cilium-linux-amd64.tar.gz.sha256sum
  3. sudo tar xzvfC cilium-linux-amd64.tar.gz /usr/local/bin
  4. rm cilium-linux-amd64.tar.gz{,.sha256sum}
  1. cilium status --wait
  2. /¯¯\
  3. /¯¯\__/¯¯\ Cilium: OK
  4. \__/¯¯\__/ Operator: OK
  5. /¯¯\__/¯¯\ Hubble: disabled
  6. \__/¯¯\__/ ClusterMesh: disabled
  7. \__/
  8. DaemonSet cilium Desired: 2, Ready: 2/2, Available: 2/2
  9. Deployment cilium-operator Desired: 2, Ready: 2/2, Available: 2/2
  10. Containers: cilium-operator Running: 2
  11. cilium Running: 2
  12. Image versions cilium quay.io/cilium/cilium:v1.9.5: 2
  13. cilium-operator quay.io/cilium/operator-generic:v1.9.5: 2

运行以下命令以验证您的集群是否具有正确的网络连接:
  1. cilium connectivity test
  2. ℹ️ Monitor aggregation detected, will skip some flow validation steps
  3. [k8s-cluster] Creating namespace for connectivity check...
  4. ---------------------------------------------------------------------------------------------------------------------
  5. 📋 Test Report
  6. ---------------------------------------------------------------------------------------------------------------------
  7. 69/69 tests successful (0 warnings)

部署Hubble

生产yaml
  1. helm template cilium cilium/cilium --version 1.8.1 \
  2. --namespace kube-system \
  3. --set global.etcd.enabled=true \
  4. --set global.etcd.managed=true \
  5. --set global.hubble.enabled=true \
  6. --set global.hubble.listenAddress=":4244" \
  7. --set global.hubble.metrics.enabled="{dns,drop,tcp,flow,port-distribution,icmp,http}" \
  8. --set global.hubble.relay.enabled=true \
  9. --set global.hubble.ui.enabled=true > hubble.yaml
  10. kubectl apply -f hubble.yaml
  11. # 包含两个组件
  12. # - daemonset hubble
  13. # - deployment hubble UI
  14. kubectl get pod -n kube-system |grep hubble
  15. hubble-67ldp 1/1 Running 0 21h
  16. hubble-f287p 1/1 Running 0 21h
  17. hubble-fxzms 1/1 Running 0 21h
  18. hubble-tlq64 1/1 Running 1 21h
  19. hubble-ui-5f9fc85849-hkzkr 1/1 Running 0 15h
  20. hubble-vpxcb 1/1 Running 0 21h

kubectl apply -f hubble-ui-nodeport-svc.yaml

  1. hubble-ui-nodeport-svc.yaml
  2. kind: Service
  3. apiVersion: v1
  4. metadata:
  5. namespace: kube-system
  6. name: hubble-ui-np
  7. spec:
  8. selector:
  9. k8s-app: hubble-ui
  10. ports:
  11. - name: http
  12. port: 12000
  13. nodePort: 32321
  14. type: NodePort

image.png