二 Istio:在Kubernetes(k8s)集群上安裝部署istio1.14( 六 )

一旦 Operator 檢測到 IstioOperator 資源,它將開始安裝 Istio 。整個過程可能需要5分鐘左右 。
為了檢查安裝的狀態,我們可以看看 istio-system 命名空間中的 Pod 的狀態 。
【二 Istio:在Kubernetes(k8s)集群上安裝部署istio1.14】[root@k8scloude1 istioyaml]# kubectl get pod -o wide -n istio-systemNAMEREADYSTATUSRESTARTSAGEIPNODENOMINATED NODEREADINESS GATESistio-egressgateway-58949b7c84-k7v6f1/1Running09m20s10.244.112.173k8scloude2<none><none>istio-ingressgateway-75bc568988-9j4wv1/1Running09m20s10.244.251.238k8scloude3<none><none>istiod-84d979766b-kz5sd1/1Running010m10.244.112.130k8scloude2<none><none>當所有的 Pod 都在運行時,Operator 已經完成了 Istio 的安裝 。
6.5 啟用 sidecar 注入服務網格需要讓每個應用程序同時運行 sidecar 代理 。
要將 sidecar 代理注入到現有的 Kubernetes 部署中 , 我們可以使用 istioctl 命令中的 kube-inject 動作 。
然而,我們也可以在任意 Kubernetes 命名空間上啟用 sidecar 自動注入 。如果我們用 istio-injection=enabled 標記命名空間 , Istio 會自動為我們在該命名空間中創建的所有 Kubernetes Pod 注入 sidecar 。
讓我們通過添加標簽來啟用 microservice 命名空間的 sidecar 自動注入 。
#創建命名空間[root@k8scloude1 istioyaml]# kubectl create ns microservicenamespace/microservice created[root@k8scloude1 istioyaml]# kubectl label namespace microservice istio-injection=enablednamespace/microservice labeled要檢查命名空間是否被標記,請運行下面的命令 。microservice 命名空間應該是唯一一個啟用了該值的命名空間 。
[root@k8scloude1 istioyaml]# kubectl get namespace -L istio-injectionNAMESTATUSAGEISTIO-INJECTIONapp-team1Active163dmicroserviceActive3m39senabledmy-appActive162dnetworkActive219dns1Active256d#或者這樣查詢[root@k8scloude1 istioyaml]# kubectl get namespace -l istio-injection=enabledNAMESTATUSAGEmicroserviceActive6m56s現在我們可以嘗試在 microservice 命名空間創建一個 Deployment,并觀察注入的代理 。我們將創建一個名為 mynginx 的 Deployment,使用hub.c.163.com/library/nginx:latest鏡像的單一容器 。
[root@k8scloude1 istioyaml]# kubectl create deployment mynginx --image=hub.c.163.com/library/nginx:latest -n microservicedeployment.apps/mynginx created如果我們看一下 Pod , 你會發現 Pod 里有兩個容器 。
[root@k8scloude1 istioyaml]# kubectl get deployment -n microserviceNAMEREADYUP-TO-DATEAVAILABLEAGEmynginx1/11127s[root@k8scloude1 istioyaml]# kubectl get pod -n microserviceNAMEREADYSTATUSRESTARTSAGEmynginx-5cb948ffc5-wv29l2/2Running035s同樣地,描述 Pod 時會顯示 Kubernetes 同時創建了一個 nginx 容器和一個 istio-proxy 容器:
[root@k8scloude1 istioyaml]# kubectl describe pod mynginx-5cb948ffc5-wv29l -n microserviceName:mynginx-5cb948ffc5-wv29l......Events:TypeReasonAgeFromMessage-------------------------NormalScheduled12mdefault-schedulerSuccessfully assigned microservice/mynginx-5cb948ffc5-wv29l to k8scloude2NormalPulled12mkubeletContainer image "docker.io/istio/proxyv2:1.14.3" already present on machineNormalCreated12mkubeletCreated container istio-initNormalStarted12mkubeletStarted container istio-initNormalPulling12mkubeletPulling image "hub.c.163.com/library/nginx:latest"NormalPulled12mkubeletSuccessfully pulled image "hub.c.163.com/library/nginx:latest" in 2.24360029sNormalCreated12mkubeletCreated container nginxNormalStarted12mkubeletStarted container nginxNormalPulled12mkubeletContainer image "docker.io/istio/proxyv2:1.14.3" already present on machineNormalCreated12mkubeletCreated container istio-proxyNormalStarted12mkubeletStarted container istio-proxy運行下面的命令,刪除deployment:
[root@k8scloude1 istioyaml]# kubectl delete deployment mynginx -n microservicedeployment.apps "mynginx" deleted[root@k8scloude1 istioyaml]# kubectl get deployment -n microserviceNo resources found in microservice namespace.[root@k8scloude1 istioyaml]# kubectl get pod -n microserviceNo resources found in microservice namespace.6.6 更新和卸載 Istio如果我們想更新當前的安裝或改變配置文件,那么需要更新先前部署的 IstioOperator 資源 。
要刪除安裝,我們必須刪除 IstioOperator,例如:
[root@k8scloude1 istioyaml]# kubectl get istiooperator -n istio-systemNAMEREVISIONSTATUSAGEdemo-istio-installHEALTHY45m[root@k8scloude1 istioyaml]# kubectl delete istiooperator demo-istio-install -n istio-system在 Operator 刪除了Istio 后,運行下面的命令來刪除 Operator:

推薦閱讀