使用 Cilium 作爲網絡插件部署 K8s + KubeSphere

Cilium 簡介

Cilium 是一個用於容器網絡領域的開源項目,主要是面向容器而使用,用於提供並透明地保護應用程序工作負載(如應用程序容器或進程)之間的網絡連接和負載均衡。

Cilium 在第 3/4 層運行,以提供傳統的網絡和安全服務,還在第 7 層運行,以保護現代應用協議(如 HTTP, gRPC 和 Kafka)的使用。 Cilium 被集成到常見的容器編排框架中,如 Kubernetes 和 Mesos。

Cilium 的底層基礎是 BPF,Cilium 的工作模式是生成內核級別的 BPF 程序與容器直接交互。區別於爲容器創建 overlay 網絡,Cilium 允許每個容器分配一個 IPv6 地址(或者 IPv4 地址),使用容器標籤而不是網絡路由規則去完成容器間的網絡隔離。它還包含創建並實施 Cilium 規則的編排系統的整合。

以上簡介來源於 oschina

對 Cilium 的性能比較感興趣的讀者可以參考這篇文章: 最強 CNI 基準測試:Cilium 網絡性能分析

系統要求

Linux Kernel >= 4.9.17 更多信息請查看 Cilium 系統要求

環境

以一臺 Ubuntu Server 20.04.1 LTS 64bit 爲例 | name | ip | role | | --- | ---| --- | | node1 | 10.160.6.136 | etcd, master, worker |

下載安裝包

sudo wget https://github.com/kubesphere/kubekey/releases/download/v1.1.0/kubekey-v1.1.0-linux-64bit.deb

使用 cilium 作爲網絡插件部署 KubeSphere

1.安裝 KubeKey

sudo dpkg -i kubekey-v1.1.0-linux-64bit.deb

2.生成配置文件

sudo kk create config --with-kubernetes v1.19.8

3.修改配置文件,將網絡插件修改爲 cilium 注意將spec.network.plugin 的值修改爲 cilium

sudo vi config-sample.yaml
apiVersion: kubekey.kubesphere.io/v1alpha1
kind: Cluster
metadata:
  name: sample
spec:
  hosts:
  - {name: node1, address: 10.160.6.136, internalAddress: 10.160.6.136, user: ubuntu, password: ********}
  roleGroups:
    etcd:
    - node1
    master: 
    - node1
    worker:
    - node1
  controlPlaneEndpoint:
    domain: lb.kubesphere.local
    address: ""
    port: 6443
  kubernetes:
    version: v1.19.8
    imageRepo: kubesphere
    clusterName: cluster.local
  network:
    plugin: cilium
    kubePodsCIDR: 10.233.64.0/18
    kubeServiceCIDR: 10.233.0.0/18
  registry:
    registryMirrors: []
    insecureRegistries: []
  addons: []

4.部署依賴

sudo kk init os -f config-sample.yaml

5.部署 KubeSphere

sudo kk create cluster -f config-sample.yaml --with-kubesphere v3.1.0

看到如下提示說明安裝完成

#####################################################
###              Welcome to KubeSphere!           ###
#####################################################

Console: http://10.160.6.136:30880
Account: admin
Password: P@88w0rd

NOTES:
  1. After you log into the console, please check the
     monitoring status of service components in
     "Cluster Management". If any service is not
     ready, please wait patiently until all components 
     are up and running.
  2. Please change the default password after login.

#####################################################
https://kubesphere.io             2021-05-18 17:15:03
#####################################################
INFO[17:15:16 CST] Installation is complete.

6.登陸 KubeSphere console

7.檢查狀態

安裝hubble UI

Hubble 是專門爲網絡可視化設計的,能夠利用 Cilium 提供的 eBPF 數據路徑,獲得對 Kubernetes 應用和服務的網絡流量的深度可見性。這些網絡流量信息可以對接 Hubble CLI、UI 工具,可以通過交互式的方式快速診斷如與 DNS 相關的問題。除了 Hubble 自身的監控工具,還可以對接主流的雲原生監控體系——Prometheus 和 Grafana,實現可擴展的監控策略。

Hubble 的安裝很簡單,直接執行以下命令:

kubectl apply -f https://raw.githubusercontent.com/cilium/cilium/1.9.7/install/kubernetes/quick-hubble-install.yaml

檢查狀態

安裝 demo 服務,並在 hubble UI 查看服務依賴關係

1.安裝 demo

kubectl create -f https://raw.githubusercontent.com/cilium/cilium/1.9.7/examples/minikube/http-sw-app.yaml

2.將 hubble UI 服務類型修改爲 NodePort

3.訪問 demo

kubectl exec xwing -- curl -s -XPOST deathstar.default.svc.cluster.local/v1/request-landing
Ship landed
kubectl exec tiefighter -- curl -s -XPOST deathstar.default.svc.cluster.local/v1/request-landing
Ship landed

4.在 hubble 上 查看服務依賴關係

如果想開啓網絡 7 層的可視化觀察,就需要對目標 Pod 進行 annotations ,感興趣可以看Cilium 的官方文檔

總結

從使用體驗來看,Cilium 已經可以滿足絕大多數的容器網絡需求,特別是 Hubble 使用原生的方式實現了數據平面的可視化,比 Istio 高明多了。相信用不了多久,Cilium 便會成爲 Kubernetes 社區使用最多的網絡方案。

本文由博客一文多發平臺 OpenWrite 發佈!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章