附註:
- 此教學課程需要存取 Oracle Cloud。若要註冊免費帳戶,請參閱開始使用 Oracle Cloud Infrastructure Free Tier 。
- 它使用 Oracle Cloud Infrastructure 憑證、租用戶及區間的範例值。完成實驗室時,請將這些值取代為您雲端環境特有的值。
使用 Cilium 在 Oracle Cloud Infrastructure Container Engine for Kubernetes 中提供網路服務
簡介
當我們使用 Oracle Cloud Infrastructure Container Engine for Kubernetes (OKE) 部署新的 Kubernetes 叢集時,安裝的預設容器網路介面 (CNI) 外掛程式為 OCI VCN 原生 CNI 外掛程式。有了雲端原生運算,您只要選擇其他 CNI Plugin,就可以彈性地選擇向容器平台提供網路 (安全) 服務的方法。在本教學課程中,我們將使用 OKE 搭配 Flannel CNI 外掛程式來部署新的 Kubernetes 叢集,並將其變更為 Cilium CNI 外掛程式。與 OCI VCN 原生 CNI Plugin 和 Flannel 相比,Cilium 提供其他網路 (安全) 功能。
目標
- 使用自訂建立方法在 Oracle Cloud Infrastructure Container Engine for Kubernetes 平台上部署新的 Kubernetes 叢集。在此部署期間,我們將選取 Flannel CNI 外掛程式,然後部署 Cilium CNI 外掛程式並移除 Flannel CNI 外掛程式,以便 Cilium 是適用於雲端原生應用程式之網路 (安全性) 服務的主要 CNI 外掛程式,並使用 Cilium CNI 外掛程式來部署與測試 NetworkPolicy 與 LoadBalancer 服務。
作業 1:使用 OKE 部署 Kubernetes 叢集
如需有關不同 OKE 部署模型的詳細資訊,請參閱網路資源組態範例。
OKE 部署模型範例如下:
-
範例 1:具有 Flannel CNI Plugin、Public Kubernetes API 端點、Private Worker 節點以及公用負載平衡器的叢集。
-
範例 2:具有 Flannel CNI Plugin、Private Kubernetes API 端點、Private Worker 節點以及公用負載平衡器的叢集。
-
範例 3:使用 OCI CNI Plugin、Public Kubernetes API 端點、Private Worker 節點以及公用負載平衡器的叢集。
-
範例 4:使用 OCI CNI Plugin、Private Kubernetes API 端點、Private Worker 節點以及公用負載平衡器的叢集。
對於此教學課程,我們將選取範例 1 部署模型。我們已經在此處說明如何部署範例 3 :建立新的 Kubernetes 叢集並驗證元件。
-
按一下漢堡功能表。
- 按一下開發人員服務。
- 按一下 Kubernetes 叢集 (OKE) 。
-
按一下建立叢集。
- 選取自訂建立。
- 按一下送出。
-
請輸入下列資訊。
- 輸入叢集名稱。
- 請選取一個區間。
- 選取 Kubernetes 版本。
- 按下一步。
-
在網路設定中,輸入下列資訊。
- 選取 Flannel overlay 作為網路類型。
- 選取要用於部署新 Kubernetes 叢集的 VCN。若要建立 VCN,請參閱建立新的 VCN 。
- 選取您所選 VCN 內的子網路,以提供 IP 位址給 Kubernetes 服務。若要建立子網路,請參閱在 VCN 內建立專用子網路。
- 選取您所選 VCN 內的子網路,以提供 IP 位址給 Kubernetes API 端點。
- 選取指派公用 IP 位址給 API 端點。
- 按下一步。
-
在節點集區 (工作節點) 中,輸入下列資訊。我們可以選擇不同的設定,但我們將會嘗試保持相同。
- 請選取一個區間。
- 選取 Kubernetes 版本。
- 選取可用性網域。
- 選取您所選 VCN 中的子網路,以提供 IP 位址給 Kubernetes 工作節點。
- 選取您要用來放置工作節點的容錯域。
- 按下一步。
- 審閱網路資訊。
- 向下拉清單。
- 複查叢集資訊。
- 向下拉清單。
- 複查節點集區資訊。
- 向下拉清單。
- 請勿選取建立基本叢集。
- 按一下建立叢集。
- 複查不同元件的狀態。
- 按一下關閉。
-
請複查狀態為 CREATING 。
- 確認狀態為 ACTIVE 。
- 向下拉清單。
- 按一下節點集區。
- 請注意,集區中的工作節點仍為建立中。
- 請注意,集區中的工作節點為作用中。
- 按一下節點集區名稱。
-
向下拉清單。
-
請注意,所有節點都是就緒和作用中。
您可以在下列圖表中找到此部署的視覺化呈現。
-
瀏覽至開發人員服務和 Kubernetes 叢集 (OKE) 。按一下新部署的 Kubernetes 叢集。
-
按一下存取叢集。
- 選取 Cloud Shell 存取。
- 按一下複製即可複製命令,以允許存取 Kubernetes 叢集。
- 按一下啟動 Cloud Shell 。
-
Cloud Shell 現在將會啟動。某些資訊會在背景顯示。
- 請注意,您有 Cloud Shell 存取權。
- 按一下最大化圖示,讓 Cloud Shell 視窗變大。
-
貼上複製的指令。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ oci ce cluster create-kubeconfig --cluster-id ocid1.cluster.oc1.eu-amsterdam-1.aaaaaaaaXXX --file $HOME/.kube/config --region eu-amsterdam-1 --token-version 2.0.0 --kube-endpoint PUBLIC_ENDPOINT Existing Kubeconfig file found at /home/iwan_hooge/.kube/config and new config merged into it
-
請執行下列命令來取得工作節點的相關資訊。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl get nodes NAME STATUS ROLES AGE VERSION 10.0.10.132 Ready node 11m v1.28.2 10.0.10.178 Ready node 12m v1.28.2 10.0.10.79 Ready node 12m v1.28.2
-
複查部署的工作節點。
-
工作 2:在 OKE 部署的 Kubernetes 叢集上安裝 Cilium 作為 CNI Plugin
-
驗證目前部署的 CNI Plugin (Flannel)。
-
執行下列命令。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl get all -n kube-system NAME READY STATUS RESTARTS AGE pod/coredns-69c9994dbb-6b8tk 1/1 Running 0 12m pod/coredns-69c9994dbb-qxq5j 1/1 Running 0 12m pod/coredns-69c9994dbb-xdnfc 1/1 Running 0 16m pod/csi-oci-node-h57qv 1/1 Running 1 (12m ago) 14m pod/csi-oci-node-nfrnw 1/1 Running 0 14m pod/csi-oci-node-pjqwk 1/1 Running 0 15m pod/kube-dns-autoscaler-d8d55cddd-pbfql 1/1 Running 0 16m pod/kube-flannel-ds-9tc92 1/1 Running 1 (13m ago) 14m pod/kube-flannel-ds-b8dch 1/1 Running 1 (12m ago) 14m pod/kube-flannel-ds-lbvw9 1/1 Running 0 15m pod/kube-proxy-2stzh 1/1 Running 0 15m pod/kube-proxy-8t6j4 1/1 Running 0 14m pod/kube-proxy-jxx6c 1/1 Running 0 14m pod/proxymux-client-cmmxv 1/1 Running 0 15m pod/proxymux-client-kk9bh 1/1 Running 0 14m pod/proxymux-client-mn4k9 1/1 Running 0 14m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kube-dns ClusterIP 10.96.5.5 <none> 53/UDP,53/TCP,9153/TCP 16m NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE daemonset.apps/csi-oci-node 3 3 3 3 3 <none> 16m daemonset.apps/kube-flannel-ds 3 3 3 3 3 <none> 16m daemonset.apps/kube-proxy 3 3 3 3 3 beta.kubernetes.io/os=linux 16m daemonset.apps/node-termination-handler 0 0 0 0 0 oci.oraclecloud.com/oke-is-preemptible=true 16m daemonset.apps/nvidia-gpu-device-plugin 0 0 0 0 0 <none> 16m daemonset.apps/proxymux-client 3 3 3 3 3 node.info.ds_proxymux_client=true 16m NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/coredns 3/3 3 3 16m deployment.apps/kube-dns-autoscaler 1/1 1 1 16m NAME DESIRED CURRENT READY AGE replicaset.apps/coredns-69c9994dbb 3 3 3 16m replicaset.apps/kube-dns-autoscaler-d8d55cddd 1 1 1 16m iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
請注意,Flannel CNI 外掛程式已部署為 Pod。
-
請注意,Flannel CNI 外掛程式已部署為服務。
這是已安裝 Flannel CNI Plugin 的 Kubernetes 工作節點視覺表示法。
-
-
新增 Cilium 儲存區域。
-
執行下列指令以新增 Cilium 儲存庫。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ helm repo add cilium https://helm.cilium.io/ WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /home/iwan_hooge/.kube/config WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /home/iwan_hooge/.kube/config "cilium" has been added to your repositories
-
執行下列命令以產生 Cilium 部署
YAML
檔案。iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ helm show values cilium/cilium > cilium.yaml WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /home/iwan_hooge/.kube/config WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /home/iwan_hooge/.kube/config iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
-
使用下列指令確認 Cilium
YAML
檔案存在。-
執行下列命令。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ ls cilium.yaml ssh-key-2024-02-14.key
-
確認
YAML
檔案存在。 -
執行下列命令,使用 nano 編輯器編輯
YAML
檔案。iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ nano cilium.yaml
-
-
YAML
檔案是一個大型檔案,包含許多設定、捲動檔案以尋找下列設定並更新。containerRuntime: integration: crio hubble: tls: enabled: false hubble: relay: enabled: true hubble: ui: enabled: true ipam: mode: "kubernetes" clustermesh: useAPIServer: true
-
使用
CTRL + W
捷徑來尋找關鍵字、設定或區段。- 尋找容器程式實際執行區段。
- 變更 integration 類型。
- 在 Hubble 的 TLS 組態段落中。
- 停用 TLS。
- 在中繼區段中。
- 啟用轉送。
- 在 *ui 區段中。
- 啟用 UI。
- 在 ipam 區段中。
- 將模式設定為 kubernetes 。
- 在 clustermesh 區段中。
- 將 useAPIServer 設定為
true
。 - 使用
CTRL + X
捷徑結束 nano 編輯器。
-
輸入
Y
(是) 以儲存YAML
檔案。 -
保持預設
YAML
檔案名稱。 -
儲存檔案後,您將返回終端機。
-
安裝 Cilium。
-
請執行下列命令以安裝 Cilium。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ helm install cilium cilium/cilium --namespace=kube-system -f cilium.yaml WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /home/iwan_hooge/.kube/config WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /home/iwan_hooge/.kube/config NAME: cilium LAST DEPLOYED: Thu Mar 21 10:31:04 2024 NAMESPACE: kube-system STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: You have successfully installed Cilium with Hubble Relay and Hubble UI. Your release version is 1.15.2. For any further help, visit https://docs.cilium.io/en/v1.15/gettinghelp iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
請注意,Cilium 成功安裝的訊息。
-
-
若要執行 Cilium 指令,請使用下列指令下載 Cilium 指令行介面 (CLI)。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ CILIUM_CLI_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/cilium-cli/master/stable.txt) iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ CLI_ARCH=amd64 iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ if [ "$(uname -m)" = "aarch64" ]; then CLI_ARCH=arm64; fi iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ curl -L --fail --remote-name-all https://github.com/cilium/cilium-cli/releases/download/${CILIUM_CLI_VERSION}/cilium-linux-${CLI_ARCH}.tar.gz{,.sha256sum} % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 37.5M 100 37.5M 0 0 28.7M 0 0:00:01 0:00:01 --:--:-- 53.3M % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 92 100 92 0 0 128 0 --:--:-- --:--:-- --:--:-- 0 iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ sha256sum --check cilium-linux-${CLI_ARCH}.tar.gz.sha256sum cilium-linux-arm64.tar.gz: OK
-
執行下列指令來解壓縮 Cilium CLI 應用程式。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ sudo tar xzvf cilium-linux-${CLI_ARCH}.tar.gz
-
若要確認 Cilium CLI 檔案存在,請執行下列指令。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ ls -l total 138060 -rw-r--r--. 1 iwan_hooge oci 101843096 Mar 18 17:19 cilium -rw-r--r--. 1 iwan_hooge oci 39388621 Mar 21 10:38 cilium-linux-arm64.tar.gz -rw-r--r--. 1 iwan_hooge oci 92 Mar 21 10:38 cilium-linux-arm64.tar.gz.sha256sum -rw-r--r--. 1 iwan_hooge oci 126806 Mar 21 10:29 cilium.yaml -rw-------. 1 iwan_hooge oci 1671 Feb 14 10:07 ssh-key-2024-02-14.key iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
成功壓縮之後,請注意清單中名為
cillium
的檔案。
-
-
執行下列命令以移除下載的壓縮檔。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ rm cilium-linux-${CLI_ARCH}.tar.gz{,.sha256sum}
-
使用 Cilium CLI。
-
執行下列命令以使 Cilium CLI 檔案可執行。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ chmod 777 cilium
-
執行下列命令以檢查含有 Cilium 之 Kubernetes 叢集的狀態。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ ./cilium status /¯¯\ /¯¯\__/¯¯\ Cilium: OK \__/¯¯\__/ Operator: OK /¯¯\__/¯¯\ Envoy DaemonSet: disabled (using embedded mode) \__/¯¯\__/ Hubble Relay: 1 errors \__/ ClusterMesh: OK Deployment clustermesh-apiserver Desired: 1, Ready: 1/1, Available: 1/1 Deployment cilium-operator Desired: 2, Ready: 2/2, Available: 2/2 Deployment hubble-ui Desired: 1, Unavailable: 1/1 Deployment hubble-relay Desired: 1, Unavailable: 1/1 DaemonSet cilium Desired: 3, Ready: 3/3, Available: 3/3 Containers: cilium Running: 3 cilium-operator Running: 2 hubble-ui Running: 1 clustermesh-apiserver Running: 1 hubble-relay Running: 1 Cluster Pods: 3/7 managed by Cilium Helm chart version: 1.15.2 Image versions cilium quay.io/cilium/cilium:v1.15.2@sha256:bfeb3f1034282444ae8c498dca94044df2b9c9c8e7ac678e0b43c849f0b31746: 3 cilium-operator quay.io/cilium/operator-generic:v1.15.2@sha256:4dd8f67630f45fcaf58145eb81780b677ef62d57632d7e4442905ad3226a9088: 2 hubble-ui quay.io/cilium/hubble-ui:v0.13.0@sha256:7d663dc16538dd6e29061abd1047013a645e6e69c115e008bee9ea9fef9a6666: 1 hubble-ui quay.io/cilium/hubble-ui-backend:v0.13.0@sha256:1e7657d997c5a48253bb8dc91ecee75b63018d16ff5e5797e5af367336bc8803: 1 clustermesh-apiserver quay.io/cilium/clustermesh-apiserver:v1.15.2@sha256:478c77371f34d6fe5251427ff90c3912567c69b2bdc87d72377e42a42054f1c2: 2 hubble-relay quay.io/cilium/hubble-relay:v1.15.2@sha256:48480053930e884adaeb4141259ff1893a22eb59707906c6d38de2fe01916cb0: 1 Errors: hubble-ui hubble-ui 1 pods of Deployment hubble-ui are not ready hubble-relay hubble-relay 1 pods of Deployment hubble-relay are not ready iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
備註:您會收到一些錯誤,因為某些 Pod 尚未由 Cilium 管理,因為在 Cilium 執行前啟動的 Pod。
-
此錯誤與 ClusterMesh 有關。
-
此錯誤與 Hubble UI 和 Hubble Relay 有關。
-
請注意,並非所有叢集 Pod 都由 Cilium 管理。只有 3/7 Pod 由 Cilium 管理。我們需要確保它們全部都由 Cilium 管理。
-
請注意與上述錯誤有關的一些其他錯誤訊息。
-
-
檢查並配置目前未由 Cilium 管理的 Pod。Cilium 提供了一個可以協助您識別它們的文稿 。
-
執行下列命令來下載命令檔。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ curl -sLO https://raw.githubusercontent.com/cilium/cilium/master/contrib/k8s/k8s-unmanaged.sh
-
執行下列命令讓此命令檔可執行。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ chmod +x k8s-unmanaged.sh
-
執行以下指令來執行此程序檔,並偵測需要特別注意的 Pod。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ ./k8s-unmanaged.sh Skipping pods with host networking enabled or with status not in Running or Pending phase... kube-system/clustermesh-apiserver-664b6c9c84-p49tr kube-system/hubble-relay-58d6b4cc94-kdwl4 kube-system/hubble-ui-6548d56557-w9s6t kube-system/kube-dns-autoscaler-d8d55cddd-pbfql iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
請注意,需要注意的 Pod。
-
執行以下指令來刪除需要注意的 Pod。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl -n kube-system delete pod clustermesh-apiserver-664b6c9c84-p49tr hubble-relay-58d6b4cc94-kdwl4 hubble-ui-6548d56557-w9s6t kube-dns-autoscaler-d8d55cddd-pbfql pod "clustermesh-apiserver-664b6c9c84-p49tr" deleted pod "hubble-relay-58d6b4cc94-kdwl4" deleted pod "hubble-ui-6548d56557-w9s6t" deleted pod "kube-dns-autoscaler-d8d55cddd-pbfql" deleted iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
確認已刪除的 Pod。
-
-
執行以下指令來執行此程序檔,並偵測需要再次注意的 Pod。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ ./k8s-unmanaged.sh Skipping pods with host networking enabled or with status not in Running or Pending phase... iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
請注意,已不再需要注意的 Pod,這表示現在已使用啟用 Cilium 網路來重新建立 Pod。
-
使用 Cilium 檢查 Kubernetes 叢集的狀態。
-
執行下列命令以檢查含有 Cilium 之 Kubernetes 叢集的狀態。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ ./cilium status /¯¯\ /¯¯\__/¯¯\ Cilium: OK \__/¯¯\__/ Operator: OK /¯¯\__/¯¯\ Envoy DaemonSet: disabled (using embedded mode) \__/¯¯\__/ Hubble Relay: OK \__/ ClusterMesh: OK Deployment hubble-ui Desired: 1, Ready: 1/1, Available: 1/1 Deployment cilium-operator Desired: 2, Ready: 2/2, Available: 2/2 Deployment clustermesh-apiserver Desired: 1, Ready: 1/1, Available: 1/1 DaemonSet cilium Desired: 3, Ready: 3/3, Available: 3/3 Deployment hubble-relay Desired: 1, Ready: 1/1, Available: 1/1 Containers: cilium Running: 3 hubble-ui Running: 1 hubble-relay Running: 1 cilium-operator Running: 2 clustermesh-apiserver Running: 1 Cluster Pods: 7/7 managed by Cilium Helm chart version: 1.15.2 Image versions hubble-ui quay.io/cilium/hubble-ui:v0.13.0@sha256:7d663dc16538dd6e29061abd1047013a645e6e69c115e008bee9ea9fef9a6666: 1 hubble-ui quay.io/cilium/hubble-ui-backend:v0.13.0@sha256:1e7657d997c5a48253bb8dc91ecee75b63018d16ff5e5797e5af367336bc8803: 1 hubble-relay quay.io/cilium/hubble-relay:v1.15.2@sha256:48480053930e884adaeb4141259ff1893a22eb59707906c6d38de2fe01916cb0: 1 cilium-operator quay.io/cilium/operator-generic:v1.15.2@sha256:4dd8f67630f45fcaf58145eb81780b677ef62d57632d7e4442905ad3226a9088: 2 clustermesh-apiserver quay.io/cilium/clustermesh-apiserver:v1.15.2@sha256:478c77371f34d6fe5251427ff90c3912567c69b2bdc87d72377e42a42054f1c2: 2 cilium quay.io/cilium/cilium:v1.15.2@sha256:bfeb3f1034282444ae8c498dca94044df2b9c9c8e7ac678e0b43c849f0b31746: 3 iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
請注意,所有叢集 Pod 都是由 Cilium 管理。
-
-
檢查目前部署的 CNI Plugin。
-
執行下列命令以驗證目前部署的 CNI Plugin (Flannel 和 Cilium)。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl get all -n kube-system NAME READY STATUS RESTARTS AGE pod/cilium-operator-5995454695-8c6m4 1/1 Running 0 33m pod/cilium-operator-5995454695-s28sl 1/1 Running 0 33m pod/cilium-v8phg 1/1 Running 0 33m pod/cilium-vnfng 1/1 Running 0 33m pod/cilium-w8qq9 1/1 Running 0 33m pod/clustermesh-apiserver-664b6c9c84-4gvrp 1/2 Error 1 (77s ago) 2m29s pod/coredns-69c9994dbb-c2v77 1/1 Running 0 33m pod/coredns-69c9994dbb-kjdxp 1/1 Running 0 33m pod/coredns-69c9994dbb-sqv8t 1/1 Running 0 32m pod/csi-oci-node-h57qv 1/1 Running 1 (22h ago) 22h pod/csi-oci-node-nfrnw 1/1 Running 0 22h pod/csi-oci-node-pjqwk 1/1 Running 0 22h pod/hubble-relay-58d6b4cc94-lrjls 1/1 Running 0 2m29s pod/hubble-ui-6548d56557-hnt2d 2/2 Running 0 2m29s pod/kube-dns-autoscaler-d8d55cddd-n5zv5 1/1 Running 0 2m29s pod/kube-flannel-ds-9tc92 1/1 Running 1 (22h ago) 22h pod/kube-flannel-ds-b8dch 1/1 Running 1 (22h ago) 22h pod/kube-flannel-ds-lbvw9 1/1 Running 0 22h pod/kube-proxy-2stzh 1/1 Running 0 22h pod/kube-proxy-8t6j4 1/1 Running 0 22h pod/kube-proxy-jxx6c 1/1 Running 0 22h pod/proxymux-client-cmmxv 1/1 Running 0 22h pod/proxymux-client-kk9bh 1/1 Running 0 22h pod/proxymux-client-mn4k9 1/1 Running 0 22h NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/clustermesh-apiserver NodePort 10.96.181.249 <none> 2379:32379/TCP 33m service/clustermesh-apiserver-metrics ClusterIP None <none> 9962/TCP,9963/TCP 33m service/hubble-peer ClusterIP 10.96.249.93 <none> 80/TCP 33m service/hubble-relay ClusterIP 10.96.172.180 <none> 80/TCP 33m service/hubble-ui ClusterIP 10.96.119.250 <none> 80/TCP 33m service/kube-dns ClusterIP 10.96.5.5 <none> 53/UDP,53/TCP,9153/TCP 22h NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE daemonset.apps/cilium 3 3 3 3 3 kubernetes.io/os=linux 33m daemonset.apps/csi-oci-node 3 3 3 3 3 <none> 22h daemonset.apps/kube-flannel-ds 3 3 3 3 3 <none> 22h daemonset.apps/kube-proxy 3 3 3 3 3 beta.kubernetes.io/os=linux 22h daemonset.apps/node-termination-handler 0 0 0 0 0 oci.oraclecloud.com/oke-is-preemptible=true 22h daemonset.apps/nvidia-gpu-device-plugin 0 0 0 0 0 <none> 22h daemonset.apps/proxymux-client 3 3 3 3 3 node.info.ds_proxymux_client=true 22h NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/cilium-operator 2/2 2 2 33m deployment.apps/clustermesh-apiserver 0/1 1 0 33m deployment.apps/coredns 3/3 3 3 22h deployment.apps/hubble-relay 1/1 1 1 33m deployment.apps/hubble-ui 1/1 1 1 33m deployment.apps/kube-dns-autoscaler 1/1 1 1 22h NAME DESIRED CURRENT READY AGE replicaset.apps/cilium-operator-5995454695 2 2 2 33m replicaset.apps/clustermesh-apiserver-664b6c9c84 1 1 0 33m replicaset.apps/coredns-69c9994dbb 3 3 3 22h replicaset.apps/hubble-relay-58d6b4cc94 1 1 1 33m replicaset.apps/hubble-ui-6548d56557 1 1 1 33m replicaset.apps/kube-dns-autoscaler-d8d55cddd 1 1 1 22h iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
請注意,Cilium CNI 外掛程式已存在。
-
請注意,Flannel CNI 外掛程式也存在。
這是已安裝 Flannel 和 Cilium CNI Plugin 的 Kubernetes 工作節點視覺化表示法。
-
-
刪除 Flannel CNI 外掛程式。
-
執行以下指令來刪除 Flannel CNI 外掛程式。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl delete -n kube-system daemonset kube-flannel-ds daemonset.apps "kube-flannel-ds" deleted iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
請注意,Flannel CNI 外掛程式已成功刪除的訊息。
-
-
檢查目前部署的 CNI Plugin。
-
執行下列命令以驗證目前部署的 CNI Plugin (Cilium)。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl get all -n kube-system NAME READY STATUS RESTARTS AGE pod/cilium-operator-5995454695-8c6m4 1/1 Running 0 35m pod/cilium-operator-5995454695-s28sl 1/1 Running 0 35m pod/cilium-v8phg 1/1 Running 0 35m pod/cilium-vnfng 1/1 Running 0 35m pod/cilium-w8qq9 1/1 Running 0 35m pod/clustermesh-apiserver-664b6c9c84-4gvrp 2/2 Running 3 (50s ago) 4m28s pod/coredns-69c9994dbb-c2v77 1/1 Running 0 35m pod/coredns-69c9994dbb-kjdxp 1/1 Running 0 35m pod/coredns-69c9994dbb-sqv8t 1/1 Running 0 34m pod/csi-oci-node-h57qv 1/1 Running 1 (22h ago) 22h pod/csi-oci-node-nfrnw 1/1 Running 0 22h pod/csi-oci-node-pjqwk 1/1 Running 0 22h pod/hubble-relay-58d6b4cc94-lrjls 1/1 Running 0 4m28s pod/hubble-ui-6548d56557-hnt2d 2/2 Running 0 4m28s pod/kube-dns-autoscaler-d8d55cddd-n5zv5 1/1 Running 0 4m28s pod/kube-proxy-2stzh 1/1 Running 0 22h pod/kube-proxy-8t6j4 1/1 Running 0 22h pod/kube-proxy-jxx6c 1/1 Running 0 22h pod/proxymux-client-cmmxv 1/1 Running 0 22h pod/proxymux-client-kk9bh 1/1 Running 0 22h pod/proxymux-client-mn4k9 1/1 Running 0 22h NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/clustermesh-apiserver NodePort 10.96.181.249 <none> 2379:32379/TCP 35m service/clustermesh-apiserver-metrics ClusterIP None <none> 9962/TCP,9963/TCP 35m service/hubble-peer ClusterIP 10.96.249.93 <none> 80/TCP 35m service/hubble-relay ClusterIP 10.96.172.180 <none> 80/TCP 35m service/hubble-ui ClusterIP 10.96.119.250 <none> 80/TCP 35m service/kube-dns ClusterIP 10.96.5.5 <none> 53/UDP,53/TCP,9153/TCP 22h NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE daemonset.apps/cilium 3 3 3 3 3 kubernetes.io/os=linux 35m daemonset.apps/csi-oci-node 3 3 3 3 3 <none> 22h daemonset.apps/kube-proxy 3 3 3 3 3 beta.kubernetes.io/os=linux 22h daemonset.apps/node-termination-handler 0 0 0 0 0 oci.oraclecloud.com/oke-is-preemptible=true 22h daemonset.apps/nvidia-gpu-device-plugin 0 0 0 0 0 <none> 22h daemonset.apps/proxymux-client 3 3 3 3 3 node.info.ds_proxymux_client=true 22h NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/cilium-operator 2/2 2 2 35m deployment.apps/clustermesh-apiserver 1/1 1 1 35m deployment.apps/coredns 3/3 3 3 22h deployment.apps/hubble-relay 1/1 1 1 35m deployment.apps/hubble-ui 1/1 1 1 35m deployment.apps/kube-dns-autoscaler 1/1 1 1 22h NAME DESIRED CURRENT READY AGE replicaset.apps/cilium-operator-5995454695 2 2 2 35m replicaset.apps/clustermesh-apiserver-664b6c9c84 1 1 1 35m replicaset.apps/coredns-69c9994dbb 3 3 3 22h replicaset.apps/hubble-relay-58d6b4cc94 1 1 1 35m replicaset.apps/hubble-ui-6548d56557 1 1 1 35m replicaset.apps/kube-dns-autoscaler-d8d55cddd 1 1 1 22h iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
請注意,Cilium CNI 外掛程式已存在,並且已移除 Flannel CNI 外掛程式。
這是安裝 Cilium CNI Plugin 的 Kubernetes 工作節點視覺化表示法。
-
-
可用來驗證 Cilium 安裝位置的其他命令。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl -n kube-system get pods -l k8s-app=cilium NAME READY STATUS RESTARTS AGE cilium-v8phg 1/1 Running 0 22h cilium-vnfng 1/1 Running 0 22h cilium-w8qq9 1/1 Running 0 22h iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
使用 Cilium 檢查 Kubernetes 叢集的狀態。
-
執行下列命令以檢查含有 Cilium 之 Kubernetes 叢集的狀態。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ ./cilium status /¯¯\ /¯¯\__/¯¯\ Cilium: OK \__/¯¯\__/ Operator: OK /¯¯\__/¯¯\ Envoy DaemonSet: disabled (using embedded mode) \__/¯¯\__/ Hubble Relay: OK \__/ ClusterMesh: OK Deployment clustermesh-apiserver Desired: 1, Ready: 1/1, Available: 1/1 Deployment cilium-operator Desired: 2, Ready: 2/2, Available: 2/2 Deployment hubble-ui Desired: 1, Ready: 1/1, Available: 1/1 Deployment hubble-relay Desired: 1, Ready: 1/1, Available: 1/1 DaemonSet cilium Desired: 3, Ready: 3/3, Available: 3/3 Containers: cilium Running: 3 cilium-operator Running: 2 hubble-ui Running: 1 clustermesh-apiserver Running: 1 hubble-relay Running: 1 Cluster Pods: 7/7 managed by Cilium Helm chart version: 1.15.2 Image versions cilium quay.io/cilium/cilium:v1.15.2@sha256:bfeb3f1034282444ae8c498dca94044df2b9c9c8e7ac678e0b43c849f0b31746: 3 cilium-operator quay.io/cilium/operator-generic:v1.15.2@sha256:4dd8f67630f45fcaf58145eb81780b677ef62d57632d7e4442905ad3226a9088: 2 hubble-ui quay.io/cilium/hubble-ui:v0.13.0@sha256:7d663dc16538dd6e29061abd1047013a645e6e69c115e008bee9ea9fef9a6666: 1 hubble-ui quay.io/cilium/hubble-ui-backend:v0.13.0@sha256:1e7657d997c5a48253bb8dc91ecee75b63018d16ff5e5797e5af367336bc8803: 1 clustermesh-apiserver quay.io/cilium/clustermesh-apiserver:v1.15.2@sha256:478c77371f34d6fe5251427ff90c3912567c69b2bdc87d72377e42a42054f1c2: 2 hubble-relay quay.io/cilium/hubble-relay:v1.15.2@sha256:48480053930e884adaeb4141259ff1893a22eb59707906c6d38de2fe01916cb0: 1 iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
請注意,所有叢集 Pod 都是由 Cilium 管理。
-
-
Cilium 內建的連線測試可以測試 Kubernetes 叢集內的網路。執行下列命令以執行 Cilium 連線測試。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ ./cilium connectivity test ℹ️ Monitor aggregation detected, will skip some flow validation steps ✨ [cluster-c6e7ypjgkyq] Creating namespace cilium-test for connectivity check... ✨ [cluster-c6e7ypjgkyq] Deploying echo-same-node service... ✨ [cluster-c6e7ypjgkyq] Deploying DNS test server configmap... ✨ [cluster-c6e7ypjgkyq] Deploying same-node deployment... ✨ [cluster-c6e7ypjgkyq] Deploying client deployment... ✨ [cluster-c6e7ypjgkyq] Deploying client2 deployment... ✨ [cluster-c6e7ypjgkyq] Deploying client3 deployment... ✨ [cluster-c6e7ypjgkyq] Deploying echo-other-node service... ✨ [cluster-c6e7ypjgkyq] Deploying other-node deployment... ✨ [host-netns] Deploying cluster-c6e7ypjgkyq daemonset... ✨ [host-netns-non-cilium] Deploying cluster-c6e7ypjgkyq daemonset... ℹ️ Skipping tests that require a node Without Cilium ⌛ [cluster-c6e7ypjgkyq] Waiting for deployment cilium-test/client to become ready... ⌛ [cluster-c6e7ypjgkyq] Waiting for deployment cilium-test/client2 to become ready... ⌛ [cluster-c6e7ypjgkyq] Waiting for deployment cilium-test/echo-same-node to become ready... ⌛ [cluster-c6e7ypjgkyq] Waiting for deployment cilium-test/client3 to become ready... ⌛ [cluster-c6e7ypjgkyq] Waiting for deployment cilium-test/echo-other-node to become ready... ⌛ [cluster-c6e7ypjgkyq] Waiting for pod cilium-test/client-69748f45d8-pxzz5 to reach DNS server on cilium-test/echo-same-node-66b5db75b9-hxjws pod... ⌛ [cluster-c6e7ypjgkyq] Waiting for pod cilium-test/client2-56896f78f8-5tzsv to reach DNS server on cilium-test/echo-same-node-66b5db75b9-hxjws pod... ⌛ [cluster-c6e7ypjgkyq] Waiting for pod cilium-test/client3-5f56bc568c-xx8kd to reach DNS server on cilium-test/echo-same-node-66b5db75b9-hxjws pod... ⌛ [cluster-c6e7ypjgkyq] Waiting for pod cilium-test/client3-5f56bc568c-xx8kd to reach DNS server on cilium-test/echo-other-node-d8c5659dc-mhpkk pod... ⌛ [cluster-c6e7ypjgkyq] Waiting for pod cilium-test/client-69748f45d8-pxzz5 to reach DNS server on cilium-test/echo-other-node-d8c5659dc-mhpkk pod... ⌛ [cluster-c6e7ypjgkyq] Waiting for pod cilium-test/client2-56896f78f8-5tzsv to reach DNS server on cilium-test/echo-other-node-d8c5659dc-mhpkk pod... ⌛ [cluster-c6e7ypjgkyq] Waiting for pod cilium-test/client-69748f45d8-pxzz5 to reach default/kubernetes service... ⌛ [cluster-c6e7ypjgkyq] Waiting for pod cilium-test/client2-56896f78f8-5tzsv to reach default/kubernetes service... ⌛ [cluster-c6e7ypjgkyq] Waiting for pod cilium-test/client3-5f56bc568c-xx8kd to reach default/kubernetes service... ⌛ [cluster-c6e7ypjgkyq] Waiting for Service cilium-test/echo-other-node to become ready... ⌛ [cluster-c6e7ypjgkyq] Waiting for Service cilium-test/echo-other-node to be synchronized by Cilium pod kube-system/cilium-v8phg ⌛ [cluster-c6e7ypjgkyq] Waiting for Service cilium-test/echo-other-node to be synchronized by Cilium pod kube-system/cilium-vnfng ⌛ [cluster-c6e7ypjgkyq] Waiting for Service cilium-test/echo-same-node to become ready... ⌛ [cluster-c6e7ypjgkyq] Waiting for Service cilium-test/echo-same-node to be synchronized by Cilium pod kube-system/cilium-v8phg ⌛ [cluster-c6e7ypjgkyq] Waiting for Service cilium-test/echo-same-node to be synchronized by Cilium pod kube-system/cilium-vnfng ⌛ [cluster-c6e7ypjgkyq] Waiting for NodePort 10.0.10.132:31758 (cilium-test/echo-other-node) to become ready... ⌛ [cluster-c6e7ypjgkyq] Waiting for NodePort 10.0.10.132:31787 (cilium-test/echo-same-node) to become ready... ⌛ [cluster-c6e7ypjgkyq] Waiting for NodePort 10.0.10.178:31758 (cilium-test/echo-other-node) to become ready... ⌛ [cluster-c6e7ypjgkyq] Waiting for NodePort 10.0.10.178:31787 (cilium-test/echo-same-node) to become ready... ⌛ [cluster-c6e7ypjgkyq] Waiting for NodePort 10.0.10.79:31758 (cilium-test/echo-other-node) to become ready... ⌛ [cluster-c6e7ypjgkyq] Waiting for NodePort 10.0.10.79:31787 (cilium-test/echo-same-node) to become ready... ⌛ [cluster-c6e7ypjgkyq] Waiting for DaemonSet cilium-test/host-netns-non-cilium to become ready... ⌛ [cluster-c6e7ypjgkyq] Waiting for DaemonSet cilium-test/host-netns to become ready... ℹ️ Skipping IPCache check 🔭 Enabling Hubble telescope... ⚠️ Unable to contact Hubble Relay, disabling Hubble telescope and flow validation: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing: dial tcp 127.0.0.1:4245: connect: connection refused" ℹ️ Expose Relay locally with: cilium hubble enable cilium hubble port-forward& ℹ️ Cilium version: 1.15.2 🏃 Running 75 tests ... [=] Test [no-unexpected-packet-drops] [1/75] ... [=] Test [no-policies] [2/75] ......................................................... [=] Skipping Test [no-policies-from-outside] [3/75] (skipped by condition) [=] Test [no-policies-extra] [4/75] ................................................ [=] Test [allow-all-except-world] [5/75] .................................... [=] Test [client-ingress] [6/75] ...... [=] Test [client-ingress-knp] [7/75] ...... [=] Test [allow-all-with-metrics-check] [8/75] ...... [=] Test [all-ingress-deny] [9/75] ............ [=] Skipping Test [all-ingress-deny-from-outside] [10/75] (skipped by condition) [=] Test [all-ingress-deny-knp] [11/75] ............ [=] Test [all-egress-deny] [12/75] ........................ [=] Test [all-egress-deny-knp] [13/75] ........................ [=] Test [all-entities-deny] [14/75] ............ [=] Test [cluster-entity] [15/75] ... [=] Skipping Test [cluster-entity-multi-cluster] [16/75] (skipped by condition) [=] Test [host-entity-egress] [17/75] .................. [=] Test [host-entity-ingress] [18/75] ...... [=] Test [echo-ingress] [19/75] ...... [=] Skipping Test [echo-ingress-from-outside] [20/75] (skipped by condition) [=] Test [echo-ingress-knp] [21/75] ...... [=] Test [client-ingress-icmp] [22/75] ...... [=] Test [client-egress] [23/75] ...... [=] Test [client-egress-knp] [24/75] ...... [=] Test [client-egress-expression] [25/75] ...... [=] Test [client-egress-expression-knp] [26/75] ...... [=] Test [client-with-service-account-egress-to-echo] [27/75] ...... [=] Test [client-egress-to-echo-service-account] [28/75] ...... [=] Test [to-entities-world] [29/75] ......... [=] Test [to-cidr-external] [30/75] ...... [=] Test [to-cidr-external-knp] [31/75] ...... [=] Skipping Test [from-cidr-host-netns] [32/75] (skipped by condition) [=] Test [echo-ingress-from-other-client-deny] [33/75] .......... [=] Test [client-ingress-from-other-client-icmp-deny] [34/75] ............ [=] Test [client-egress-to-echo-deny] [35/75] ............ [=] Test [client-ingress-to-echo-named-port-deny] [36/75] .... [=] Test [client-egress-to-echo-expression-deny] [37/75] .... [=] Test [client-with-service-account-egress-to-echo-deny] [38/75] .... [=] Test [client-egress-to-echo-service-account-deny] [39/75] .. [=] Test [client-egress-to-cidr-deny] [40/75] ...... [=] Test [client-egress-to-cidr-deny-default] [41/75] ...... [=] Test [health] [42/75] ... [=] Skipping Test [north-south-loadbalancing] [43/75] (Feature node-without-cilium is disabled) [=] Test [pod-to-pod-encryption] [44/75] . [=] Test [node-to-node-encryption] [45/75] ... [=] Skipping Test [egress-gateway] [46/75] (skipped by condition) [=] Skipping Test [egress-gateway-excluded-cidrs] [47/75] (Feature enable-ipv4-egress-gateway is disabled) [=] Skipping Test [pod-to-node-cidrpolicy] [48/75] (Feature cidr-match-nodes is disabled) [=] Skipping Test [north-south-loadbalancing-with-l7-policy] [49/75] (Feature node-without-cilium is disabled) [=] Test [echo-ingress-l7] [50/75] .................. [=] Test [echo-ingress-l7-named-port] [51/75] .................. [=] Test [client-egress-l7-method] [52/75] .................. [=] Test [client-egress-l7] [53/75] ............... [=] Test [client-egress-l7-named-port] [54/75] ............... [=] Skipping Test [client-egress-l7-tls-deny-without-headers] [55/75] (Feature secret-backend-k8s is disabled) [=] Skipping Test [client-egress-l7-tls-headers] [56/75] (Feature secret-backend-k8s is disabled) [=] Skipping Test [client-egress-l7-set-header] [57/75] (Feature secret-backend-k8s is disabled) [=] Skipping Test [echo-ingress-auth-always-fail] [58/75] (Feature mutual-auth-spiffe is disabled) [=] Skipping Test [echo-ingress-mutual-auth-spiffe] [59/75] (Feature mutual-auth-spiffe is disabled) [=] Skipping Test [pod-to-ingress-service] [60/75] (Feature ingress-controller is disabled) [=] Skipping Test [pod-to-ingress-service-deny-all] [61/75] (Feature ingress-controller is disabled) [=] Skipping Test [pod-to-ingress-service-deny-ingress-identity] [62/75] (Feature ingress-controller is disabled) [=] Skipping Test [pod-to-ingress-service-deny-backend-service] [63/75] (Feature ingress-controller is disabled) [=] Skipping Test [pod-to-ingress-service-allow-ingress-identity] [64/75] (Feature ingress-controller is disabled) [=] Skipping Test [outside-to-ingress-service] [65/75] (Feature ingress-controller is disabled) [=] Skipping Test [outside-to-ingress-service-deny-world-identity] [66/75] (Feature ingress-controller is disabled) [=] Skipping Test [outside-to-ingress-service-deny-cidr] [67/75] (Feature ingress-controller is disabled) [=] Skipping Test [outside-to-ingress-service-deny-all-ingress] [68/75] (Feature ingress-controller is disabled) [=] Test [dns-only] [69/75] ............... [=] Test [to-fqdns] [70/75] ............ [=] Skipping Test [pod-to-controlplane-host] [71/75] (skipped by condition) [=] Skipping Test [pod-to-k8s-on-controlplane] [72/75] (skipped by condition) [=] Skipping Test [pod-to-controlplane-host-cidr] [73/75] (skipped by condition) [=] Skipping Test [pod-to-k8s-on-controlplane-cidr] [74/75] (skipped by condition) [=] Test [check-log-errors] [75/75] ............................. ✅ All 47 tests (555 actions) successful, 28 tests skipped, 1 scenarios skipped. iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
請注意,測試已經決定在此狀況下執行 75 個測試。
-
當測試完成時,會顯示摘要。
工作 3:部署範例 Web 應用程式和服務
-
建置範例 Web 應用程式和服務。
-
執行下列命令來部署範例 Web 應用程式和服務。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl run web --image=nginx --labels="app=web" --expose --port=80 service/web created pod/web created iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
請注意,應用程式和服務已順利建立。
-
-
檢查建置的應用程式。
-
執行下列命令以驗證已建置的應用程式。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl get pods NAME READY STATUS RESTARTS AGE web 1/1 Running 0 56s
-
請注意,Web 應用程式正在執行中。
-
執行下列命令以驗證已部署的服務。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl get deploy,svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP,12250/TCP 44h service/web ClusterIP 10.96.199.73 <none> 80/TCP 74s
-
請注意,Web 服務正在執行中。
-
-
有多種測試應用程式連線的方式,其中一種方法是開啟瀏覽器並測試是否可以存取網頁。但是當我們沒有可用的瀏覽器時,我們可以部署暫存 Pod 來進行另一個快速測試。
-
執行下列命令來部署範例 Pod 以測試 Web 應用程式連線。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl run --rm -i -t --image=alpine test-$RANDOM -- sh If you don't see a command prompt, try pressing enter. / #
-
執行下列命令,使用
wget
測試 Web 伺服器的連線。/ # wget -qO- http://web <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
-
請注意 Web 伺服器傳回的 HTML 程式碼,確認 Web 伺服器和連線正常運作。
-
執行下列指令來結束暫時 Pod。
/ # exit Session ended, resume using 'kubectl attach test-8599 -c test-8599 -i -t' command when the pod is running pod "test-8599" deleted iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
請注意,Pod 會在結束 CLI 之後立即刪除。
-
作業 4:設定 NetworkPolicy 類型的 Kubernetes 服務
Cilium CNI 外掛程式提供的網路安全性服務之一是 NetworkPolicy 類型的服務。藉由拒絕兩個 Pod 之間的連線,這是控制 Pod 之間連線的方式。
-
執行下列命令來開啟 nano 編輯器,以建立新的
YAML
檔案來實行 NetworkPolicy,以拒絕所有網路流量。iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ nano web-deny-all.yaml
-
使用
YAML
檔案中的下列內容。kind: NetworkPolicy apiVersion: networking.k8s.io/v1 metadata: name: web-deny-all spec: podSelector: matchLabels: app: web ingress: []
-
使用
CTRL + X
捷徑結束 nano 編輯器。
-
-
輸入
Y
(是) 以儲存YAML
檔案。 -
保持預設
YAML
檔案名稱。 -
驗證
YAML
檔案。-
執行下列命令以驗證新的
YAML
檔案。iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ ls -l total 138068 -rwxrwxrwx. 1 iwan_hooge oci 101843096 Mar 18 17:19 cilium -rw-r--r--. 1 iwan_hooge oci 39388621 Mar 21 10:38 cilium-linux-arm64.tar.gz -rw-r--r--. 1 iwan_hooge oci 92 Mar 21 10:38 cilium-linux-arm64.tar.gz.sha256sum -rw-r--r--. 1 iwan_hooge oci 126806 Mar 21 10:29 cilium.yaml -rwxr-xr-x. 1 iwan_hooge oci 574 Mar 21 10:58 k8s-unmanaged.sh -rw-------. 1 iwan_hooge oci 1671 Feb 14 10:07 ssh-key-2024-02-14.key -rw-r--r--. 1 iwan_hooge oci 151 Mar 22 09:11 web-deny-all.yaml
-
請注意,
web-deny-all.yaml
檔案已存在。
-
-
實作安全原則。
-
請執行下列命令以實行安全原則。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl apply -f web-deny-all.yaml networkpolicy.networking.k8s.io/web-deny-all created iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
請注意,安全原則已建立。
-
-
在部署 NetworkPolicy 之後,再次部署範例 Pod 以測試 Web 應用程式連線。
-
執行下列命令來部署範例 Pod 以測試 Web 應用程式連線。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl run --rm -i -t --image=alpine test-$RANDOM -- sh If you don't see a command prompt, try pressing Enter.
-
執行下列命令,使用
wget
測試 Web 伺服器的連線。/ # wget -qO- --timeout=2 http://web wget: download timed out
-
請注意要求逾時。
-
執行下列指令來結束暫時 Pod。
/ # exit Session ended, resume using 'kubectl attach test-26867 -c test-26867 -i -t' command when the pod is running pod "test-26867" deleted
-
-
移除安全原則,然後再次執行測試。
-
執行下列命令以刪除安全原則。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl delete -f web-deny-all.yaml
-
請注意,安全原則已移除。
-
執行下列命令來部署範例 Pod 以測試 Web 應用程式連線。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl run --rm -i -t --image=alpine test-$RANDOM -- sh If you don't see a command prompt, try pressing enter.
-
執行下列命令,使用
wget
測試 Web 伺服器的連線。 -
請注意 Web 伺服器傳回的 HTML 程式碼,這會確認 Web 伺服器和連線正常運作。
-
執行下列指令來結束暫時 Pod。
/ # exit Session ended, resume using 'kubectl attach test-26248 -c test-26248 -i -t' command when the pod is running pod "test-26248" deleted iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
請注意,Pod 會在結束 CLI 之後立即刪除。
-
工作 5:移除範例 Web 應用程式和服務
-
若要移除已部署的 Web 應用程式,請執行下列指令。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl delete service web --namespace default service "web" deleted
-
若要移除已部署的 Web 服務,請執行下列指令。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl delete pods -l app=web --namespace default pod "web" deleted
工作 6:部署範例應用程式並設定 LoadBalancer 類型的 Kubernetes 服務
我們已使用 Cilium 測試 NetworkPolicy 服務,也讓我們使用 Cilium 測試 LoadBalancer 服務。
-
建置新的範例應用程式和服務。
-
執行下列命令以部署新的範例應用程式。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl apply -f https://k8s.io/examples/application/deployment.yaml deployment.apps/nginx-deployment created
-
確認已順利建立應用程式。
-
執行下列命令以取得已部署的 Pod。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl get pods NAME READY STATUS RESTARTS AGE nginx-deployment-86dcfdf4c6-6ncvx 1/1 Running 0 10s nginx-deployment-86dcfdf4c6-qbhn2 1/1 Running 0 10s
-
複查部署的 Pod。
-
執行下列命令,將應用程式公開至 LoadBalancer 服務。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl expose deployment nginx-deployment --type=LoadBalancer --name=my-service service/my-service exposed
-
確認已順利建立服務並順利顯示應用程式。
-
執行下列命令以複查公開的服務和 IP 位址。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP,12250/TCP 46h my-service LoadBalancer 10.96.56.91 <pending> 80:32422/TCP 12s iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP,12250/TCP 46h my-service LoadBalancer 10.96.56.91 <pending> 80:32422/TCP 23s
-
請注意,外部 IP 為擱置中。
-
執行下列命令並注意已設定公用 IP 位址 (以
.88
結尾)。iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP,12250/TCP 46h my-service LoadBalancer 10.96.56.91 XXX.XXX.XXX.88 80:32422/TCP 37s iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
-
在網際網路瀏覽器中複製並貼上公用 IP 位址,然後使用 LoadBalancer 服務公用 IP 位址驗證已部署的應用程式 (使用預設網站的 Nginx Web 伺服器) 是否可以連線。
工作 7:移除 LoadBalancer 類型的範例應用程式和 Kubernetes 服務
-
執行下列命令以取得已部署的 Pod。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl get pods NAME READY STATUS RESTARTS AGE nginx-deployment-86dcfdf4c6-6ncvx 1/1 Running 0 2m54s nginx-deployment-86dcfdf4c6-qbhn2 1/1 Running 0 2m54s
-
複查部署的 Pod。
-
若要移除已部署的 Web 應用程式,請執行下列指令。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl delete deployment nginx-deployment --namespace default deployment.apps "nginx-deployment" deleted
-
確認應用程式已刪除。
-
執行下列命令以取得已部署的 Pod。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl get pods No resources found in default namespace.
-
請注意,Pod 已不再部署並已成功刪除。
-
執行下列命令以取得已部署的服務。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP,12250/TCP 46h my-service LoadBalancer 10.96.56.91 XXX.XXX.XXX.88 80:32422/TCP 2m42s
-
複查已建置的服務。
-
若要移除已部署的 LoadBalancer 服務,請執行下列命令。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl delete service my-service -n default service "my-service" deleted
-
確認已刪除服務。
-
執行下列命令以取得已部署的服務。
iwan_hooge@cloudshell:~ (eu-amsterdam-1)$ kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP,12250/TCP 46h iwan_hooge@cloudshell:~ (eu-amsterdam-1)$
-
請注意,已不再部署並順利刪除 LoadBalancer 服務。
相關連結
認可
- 作者 - Iwan Hoogendoorn (OCI 網路專家)
其他學習資源
瀏覽 docs.oracle.com/learn 的其他實驗室,或前往 Oracle Learning YouTube 頻道存取更多免費學習內容。此外,請造訪 education.oracle.com/learning-explorer 以成為 Oracle Learning Explorer。
如需產品文件,請造訪 Oracle Help Center 。
Use Cilium to Provide Networking Services in Oracle Cloud Infrastructure Container Engine for Kubernetes
F96030-01
April 2024