注意:
- 此教程需要访问 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 插件即可灵活选择向容器平台提供网络(安全)服务的方法。在本教程中,我们将使用 OKE 和 Flannel CNI 插件部署新的 Kubernetes 集群,并将其更改为 Cilium CNI 插件。与 OCI VCN 原生 CNI 插件和 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 部署模型的更多信息,请参见 Example Network Resource Configurations 。
OKE 部署模型示例包括:
-
示例 1:使用 Flannel CNI 插件、公共 Kubernetes API 端点、专用 Worker 节点和公共负载平衡器的集群。
-
示例 2:使用 Flannel CNI 插件、专用 Kubernetes API 端点、专用 Worker 节点和公共负载平衡器的集群。
-
示例 3:使用 OCI CNI 插件、公共 Kubernetes API 端点、专用 Worker 节点和公共负载平衡器的集群。
-
示例 4:使用 OCI CNI 插件、专用 Kubernetes API 端点、专用 Worker 节点和公共负载平衡器的集群。
对于本教程,我们将选择示例 1 部署模型。我们已在此处解释了如何部署示例 3 :创建新 Kubernetes 集群并验证组件。
-
单击“Hamburger(汉堡)”菜单。
- 单击开发人员服务。
- 单击 Kubernetes Clusters (OKE) 。
-
单击创建集群。
- 选择自定义创建。
- 单击提交。
-
输入以下信息。
- 输入群集名称。
- 选择区间。
- 选择 Kubernetes 版本。
- 单击下一步。
-
在网络设置中,输入以下信息。
- 选择 Flannel overlay 作为 Network Type(网络类型)。
- 选择要用于部署新 Kubernetes 集群的 VCN。要创建 VCN,请参阅创建新 VCN 。
- 选择您选择的 VCN 中的子网,以向 Kubernetes 服务提供 IP 地址。要创建子网,请参阅在 VCN 中创建专用子网。
- 选择您选择的 VCN 中的子网,以向 Kubernetes API 端点提供 IP 地址。
- 选择 Assign a public IP address to the API endpoint 。
- 单击下一步。
-
在节点池(Worker 节点)中,输入以下信息。我们可以选择不同的设置,但是我们将尝试保持不变。
- 选择区间。
- 选择 Kubernetes 版本。
- 选择可用性域。
- 选择您选择的 VCN 中的子网,以向 Kubernetes worker 节点提供 IP 地址。
- 选择要用来放置 worker 节点的容错域。
- 单击下一步。
- 复查 Network 信息。
- 向下滚动。
- 查看 Cluster 信息。
- 向下滚动。
- 查看节点池信息。
- 向下滚动。
- 请勿选择创建基本集群。
- 单击创建集群。
- 检查不同组件的状态。
- 单击关闭。
-
检查状态是否为 CREATING 。
- 验证状态是否为 ACTIVE 。
- 向下滚动。
- 单击节点池。
- 请注意,池中的 worker 节点仍处于创建状态。
- 请注意,池中的 worker 节点处于活动状态。
- 单击节点池名称。
-
向下滚动。
-
请注意,所有节点都处于 Ready 和 Active 状态。
可以在下图中找到此部署的可视化表示形式。
-
导航到 Developer Services(开发人员服务)和 Kubernetes Clusters(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
-
运行以下命令以获取有关 worker 节点的信息。
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 插件安装
-
验证当前部署的 CNI 插件 (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 插件的 Kubernetes worker 节点的可视化表示形式。
-
-
添加 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
快捷方式查找关键字、设置或节。- 找到容器运行时部分。
- 更改集成类型。
- 在 TLS configuration for Hubble 部分中。
- 禁用 TLS。
- 在 relay 部分中。
- 启用中继。
- 在 *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 命令行界面 (Command Line Interface,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)$
注:由于在 Cilium 运行之前启动了 pod,一些 pod 尚未由 Cilium 管理,因此您会收到一些错误。
-
此错误与 ClusterMesh 相关。
-
此错误与气泡 UI 和气泡中继相关。
-
请注意,并非所有 Cluster pods 都由 Cilium 管理。只有 3/7 pods 由 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,这意味着 pod 现在在启用 Cilium 网络的情况下重新创建。
-
使用 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 插件。
-
运行以下命令以验证当前部署的 CNI 插件(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 插件的 Kubernetes worker 节点的可视化表示。
-
-
删除 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 插件。
-
运行以下命令以验证当前部署的 CNI 插件 (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 插件的 Kubernetes worker 节点的可视化表示形式。
-
-
可用于验证 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)$
-
请注意,退出 CLI 后将立即删除 pod。
-
任务 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)$
-
请注意,已创建安全策略。
-
-
部署示例 pod 以在部署 NetworkPolicy 后再次测试 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)$
-
请注意,退出 CLI 后将立即删除 pod。
-
任务 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
-
查看部署的云池。
-
运行以下命令以向 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 地址复制并粘贴到 Internet 浏览器中,并验证部署的应用程序(使用默认网站的 Nginx Web 服务器)是否可以使用 LoadBalancer 服务公共 IP 地址进行访问。
任务 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
-
查看部署的云池。
-
要删除部署的 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.
-
请注意,云池不再部署并已成功删除。
-
运行以下命令以获取已部署的服务。
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 帮助中心。
Use Cilium to Provide Networking Services in Oracle Cloud Infrastructure Container Engine for Kubernetes
F96029-01
April 2024