自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

聊聊Kubernetes Without Kube-Proxy

開(kāi)發(fā) 前端
最近聽(tīng)好多朋友說(shuō),cilium很強(qiáng),勢(shì)必將成為主流。因其使用了ebpf,性能好,而且支持網(wǎng)絡(luò)策略。于是,決定花點(diǎn)時(shí)間學(xué)習(xí)一下。在通過(guò)官網(wǎng)文檔學(xué)習(xí)過(guò)程中,發(fā)現(xiàn)使用cilium作為CNI,居然可以不用安裝kube-proxy了。

本文轉(zhuǎn)載自微信公眾號(hào)「運(yùn)維開(kāi)發(fā)故事」,作者夕陽(yáng)西下。轉(zhuǎn)載本文請(qǐng)聯(lián)系運(yùn)維開(kāi)發(fā)故事公眾號(hào)。

引言

最近聽(tīng)好多朋友說(shuō),cilium很強(qiáng),勢(shì)必將成為主流。因其使用了ebpf,性能好,而且支持網(wǎng)絡(luò)策略。于是,決定花點(diǎn)時(shí)間學(xué)習(xí)一下。在通過(guò)官網(wǎng)文檔學(xué)習(xí)過(guò)程中,發(fā)現(xiàn)使用cilium作為CNI,居然可以不用安裝kube-proxy了。這讓我想起來(lái),之前在面試中被問(wèn)到的一個(gè)問(wèn)題,面試官問(wèn)我:kube-proxy是否可以不用安裝,是否有其他替代品。這下不就有答案了嘛。

順便吐槽一下,看官方文檔學(xué)習(xí),是真的有點(diǎn)難(畢竟全英文);不過(guò)還是建議大家看官方文檔學(xué)習(xí),不要翻譯成中文哦。那么接下來(lái),就由我來(lái)實(shí)操一下。

環(huán)境說(shuō)明

序號(hào) 事項(xiàng) 說(shuō)明
1 kubernetes version v1.21.3
2 cilium version v1.10.3
3 kubernetes安裝方式 kubeadm
4 cilium組網(wǎng)模式 vxlan
5 os ubuntu 18.04
6 kubernetes集群規(guī)模 1master、2node

正文

在master上初始化集群,并通過(guò)添加--skip-phases=addon/kube-proxy參數(shù)忽略kube-proxy的安裝

  1. kubeadm init   --apiserver-advertise-address=10.211.55.50   --image-repository registry.aliyuncs.com/google_containers   --kubernetes-version v1.21.3   --service-cidr=10.96.0.0/12   --pod-network-cidr=10.244.0.0/16   --ignore-preflight-errors=all --skip-phases=addon/kube-proxy 

在兩個(gè)node上執(zhí)行kubeadm join,加入集群

  1. kubeadm join 10.211.55.50:6443 --token ouez6j.02ms269v8i4psl7p --discovery-token-ca-cert-hash sha256:5fdafe0fe1adb3b60cd7bc33f033f028279a94a3944816424cc7f5bb498f6868 

使用helm(v3)來(lái)安裝cilium。先添加cilium庫(kù)

  1. helm repo add cilium https://helm.cilium.io/ 

使用如下命令安裝cilium,添加kubeProxyReplacement=strict參數(shù)

  1. helm install cilium cilium/cilium --version 1.10.3     --namespace kube-system     --set kubeProxyReplacement=strict     --set k8sServiceHost=10.211.55.50     --set k8sServicePort=6443 

檢查cilium安裝結(jié)果

  1. # 查看cilium agent,以daemonset方式部署在每個(gè)node節(jié)點(diǎn)上 
  2. root@cilium1:/# kubectl -n kube-system get pods -l k8s-app=cilium 
  3. NAME           READY   STATUS    RESTARTS   AGE 
  4. cilium-8gwg2   1/1     Running   0          8m4s 
  5. cilium-t9ffc   1/1     Running   0          8m39s 
  6. cilium-x42r6   1/1     Running   0          8m16s 
  7.  
  8. # 查看cilum operator 
  9. root@cilium1:~# kubectl get po -A -o wide |grep cilium-operator 
  10. kube-system   cilium-operator-5df88875-867hd    1/1     Running   5          41h   172.16.88.47    cilium3   <none>           <none> 
  11. kube-system   cilium-operator-5df88875-9kx8c    1/1     Running   5          41h   172.16.88.253   cilium2   <none>           <none> 

檢查是否有kube-proxy組件??梢园l(fā)現(xiàn)并沒(méi)有該組件

  1. root@cilium1:/# kubectl get po -n kube-system 
  2. NAME                              READY   STATUS    RESTARTS   AGE 
  3. cilium-8gwg2                      1/1     Running   0          10m 
  4. cilium-operator-5df88875-867hd    1/1     Running   5          27h 
  5. cilium-operator-5df88875-9kx8c    1/1     Running   5          27h 
  6. cilium-t9ffc                      1/1     Running   0          11m 
  7. cilium-x42r6                      1/1     Running   0          10m 
  8. coredns-59d64cd4d4-hbwg4          1/1     Running   1          27h 
  9. coredns-59d64cd4d4-l2pmt          1/1     Running   1          27h 
  10. etcd-cilium1                      1/1     Running   2          27h 
  11. kube-apiserver-cilium1            1/1     Running   2          27h 
  12. kube-controller-manager-cilium1   1/1     Running   2          27h 
  13. kube-scheduler-cilium1            1/1     Running   2          27h 

檢查cilium狀態(tài),確保安裝正確

  1. root@cilium1:/# kubectl exec -n kube-system  cilium-t9ffc  -- cilium status 
  2. Defaulted container "cilium-agent" out of: cilium-agent, mount-cgroup (init), clean-cilium-state (init) 
  3. KVStore:                Ok   Disabled 
  4. Kubernetes:             Ok   1.21 (v1.21.3) [linux/amd64] 
  5. Kubernetes APIs:        ["cilium/v2::CiliumClusterwideNetworkPolicy""cilium/v2::CiliumEndpoint""cilium/v2::CiliumNetworkPolicy""cilium/v2::CiliumNode""core/v1::Namespace""core/v1::Node""core/v1::Pods""core/v1::Service""discovery/v1::EndpointSlice""networking.k8s.io/v1::NetworkPolicy"
  6. KubeProxyReplacement:   Strict   [eth0 10.211.55.50 (Direct Routing)] 
  7. Cilium:                 Ok   1.10.3 (v1.10.3-4145278) 
  8. NodeMonitor:            Listening for events on 8 CPUs with 64x4096 of shared memory 
  9. Cilium health daemon:   Ok    
  10. IPAM:                   IPv4: 2/254 allocated from 10.0.0.0/24,  
  11. BandwidthManager:       Disabled 
  12. Host Routing:           Legacy 
  13. Masquerading:           BPF   [eth0]   10.0.0.0/24 [IPv4: Enabled, IPv6: Disabled] 
  14. Controller Status:      20/20 healthy 
  15. Proxy Status:           OK, ip 10.0.0.41, 0 redirects active on ports 10000-20000 
  16. Hubble:                 Ok   Current/Max Flows: 817/4095 (19.95%), Flows/s: 0.95   Metrics: Disabled 
  17. Encryption:             Disabled 
  18. Cluster health:         3/3 reachable   (2021-08-07T15:29:05Z) 

部署nginx來(lái)測(cè)試一下網(wǎng)絡(luò)聯(lián)通性

  1. # nginx deployment yaml文件 
  2. cat deployment-nginx.yaml 
  3. apiVersion: apps/v1 
  4. kind: Deployment 
  5. metadata: 
  6.   name: nginx 
  7. spec: 
  8.   selector: 
  9.     matchLabels: 
  10.       run: nginx 
  11.   replicas: 4 
  12.   template: 
  13.     metadata: 
  14.       labels: 
  15.         run: nginx 
  16.     spec: 
  17.       containers: 
  18.       - name: nginx 
  19.         image: nginx 
  20.         ports: 
  21.         - containerPort: 80 
  22.         
  23. # 創(chuàng)建nginx deployment 
  24. kubectl create -f deployment-nginx.yaml 
  25.  
  26. # 查看部署結(jié)果 
  27. root@cilium1:/# kubectl get po -o wide 
  28. NAME                     READY   STATUS    RESTARTS   AGE   IP           NODE      NOMINATED NODE   READINESS GATES 
  29. nginx-649c4b9857-8f2v5   1/1     Running   1          26h   10.0.2.212   cilium2   <none>           <none> 
  30. nginx-649c4b9857-mhsxs   1/1     Running   1          26h   10.0.1.23    cilium3   <none>           <none> 
  31. nginx-649c4b9857-qw2jj   1/1     Running   1          26h   10.0.2.69    cilium2   <none>           <none> 
  32. nginx-649c4b9857-vj9w2   1/1     Running   1          26h   10.0.1.126   cilium3 

創(chuàng)建一個(gè)nodeport service來(lái)驗(yàn)證service的可訪問(wèn)

  1. # 創(chuàng)建service 
  2. kubectl expose deployment nginx --type=NodePort --port=80 
  3.  
  4. # 查看service 
  5. root@cilium1:/# kubectl get svc nginx 
  6. NAME    TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE 
  7. nginx   NodePort   10.97.209.103   <none>        80:31126/TCP   26h 

驗(yàn)證nodeport、cluster可訪問(wèn)

  1. # 通過(guò)nodeport 
  2. root@cilium1:/# curl 127.0.0.1:31126 
  3. <!DOCTYPE html> 
  4. <html> 
  5. <head> 
  6. <title>Welcome to nginx!</title> 
  7.  
  8. # 通過(guò)service:port 
  9. root@cilium1:/# curl 10.97.209.103 
  10. <!DOCTYPE html> 
  11. <html> 
  12. <head> 
  13. <title>Welcome to nginx!</title> 
  14.  
  15. # 檢查iptables 發(fā)現(xiàn)為空 
  16. root@cilium1:/# iptables-save | grep KUBE-SVC 
  17. root@cilium1:/#  
  18.  
  19. # 檢查ciliun service 
  20. root@cilium1:/# kubectl exec -n kube-system  cilium-t9ffc  -- cilium service list 
  21. Defaulted container "cilium-agent" out of: cilium-agent, mount-cgroup (init), clean-cilium-state (init) 
  22. ID   Frontend             Service Type   Backend                   
  23. 1    10.96.0.1:443        ClusterIP      1 => 172.16.88.57:6443    
  24. 2    10.96.0.10:9153      ClusterIP      1 => 10.0.2.229:9153      
  25.                                          2 => 10.0.2.80:9153       
  26. 3    10.96.0.10:53        ClusterIP      1 => 10.0.2.229:53        
  27.                                          2 => 10.0.2.80:53         
  28. 4    10.97.209.103:80     ClusterIP      1 => 10.0.2.69:80         
  29.                                          2 => 10.0.1.23:80         
  30.                                          3 => 10.0.1.126:80        
  31.                                          4 => 10.0.2.212:80        
  32. 5    172.16.88.57:31126   NodePort       1 => 10.0.2.69:80         
  33.                                          2 => 10.0.1.23:80         
  34.                                          3 => 10.0.1.126:80        
  35.                                          4 => 10.0.2.212:80        
  36. 6    0.0.0.0:31126        NodePort       1 => 10.0.2.69:80         
  37.                                          2 => 10.0.1.23:80         
  38.                                          3 => 10.0.1.126:80        
  39.                                          4 => 10.0.2.212:80        

從上面的安裝和測(cè)試結(jié)果來(lái),雖然我們沒(méi)有安裝k8s的kube-proxy組件,但是集群依然正常。說(shuō)明kube-proxy組件確實(shí)是可以被替代的。

總結(jié)

以上雖然完成了kubernetes without kube-proxy的搭建和測(cè)試工作,但還是有很多事情沒(méi)說(shuō)明。比如使用cilium的系統(tǒng)要求、cilium是什么、有幾種組網(wǎng)模式、網(wǎng)絡(luò)策略。不過(guò)請(qǐng)不要著急,期待我后續(xù)的文章。

參考

https://docs.cilium.io/en/v1.10/gettingstarted/kubeproxy-free/#kubernetes-without-kube-proxy

https://kubernetes.io/docs/concepts/cluster-administration/addons/

 

https://helm.sh/docs/intro/install/

 

責(zé)任編輯:武曉燕 來(lái)源: 運(yùn)維開(kāi)發(fā)故事
相關(guān)推薦

2024-05-23 11:46:45

2021-10-13 16:00:53

KubeProxyIptables

2023-11-29 09:29:48

Kuberneteskube

2023-12-02 20:41:32

內(nèi)存kube

2023-10-27 08:03:29

Kubernetes開(kāi)源工具

2021-02-01 23:23:39

FiddlerCharlesWeb

2021-06-17 06:29:16

kube-vip Kubernetes開(kāi)源項(xiàng)目

2022-11-02 09:39:51

數(shù)據(jù)恢復(fù)Kubernetes

2020-12-04 14:19:08

KubernetesDocker容器

2022-03-24 07:44:41

OPA安全策略Rego

2019-12-04 10:13:58

Kubernetes存儲(chǔ)Docker

2018-11-21 10:36:29

Kubernetes存儲(chǔ)Docker

2021-09-09 07:45:25

kube-vip Kuberneteshostname

2024-02-19 10:11:00

Kubernetes網(wǎng)絡(luò)模型

2020-05-06 22:07:53

UbuntuLinux操作系統(tǒng)

2022-09-07 15:57:41

KubernetesCRD

2023-10-30 22:23:12

Cacherkube版本

2022-07-01 10:53:05

KubernetesLinux工具

2021-05-19 08:25:24

KubeEventer操作

2021-12-31 08:43:45

插件KubeScheduler
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)