k8s 安裝並試用Istio service mesh


本文根據官網的文檔整理而成,步驟包括安裝istio 0.5.1並創建一個bookinfo的微服務來測試istio的功能。

文中使用的yaml文件可以在kubernetes-handbookmanifests/istio目錄中找到,如果鏡像pull失敗,請根據官網的鏡像自行修改。

安裝環境

  • CentOS 7.4.1708
  • Docker 17.12.0-ce
  • Kubernetes 1.8.5

部署結構

Istio 的控制平面部署在 Kubernetes 中的部署架構如下圖所示。

Istio 在 Kubernetes 中的部署架構圖圖片 - Istio 在 Kubernetes 中的部署架構圖

我們可以清楚的看到 Istio 控制平面的幾個組件的部署運行的命令與開發的端口,以及端口與服務之間的映射的關系。

安裝

1.下載安裝包

下載地址:https://github.com/istio/istio/releases

下載Linux版本的當前最新版安裝包

wget https://github.com/istio/istio/releases/download/0.5.1/istio-0.5.1-linux.tar.gz 

2.解壓

解壓后,得到的目錄結構如下:

├── bin
│   └── istioctl
├── install │ ├── ansible │ ├── consul │ ├── eureka │ ├── gcp │ ├── kubernetes │ ├── README.md │ └── tools ├── istio.VERSION ├── LICENSE ├── README.md ├── samples │ ├── bookinfo │ ├── CONFIG-MIGRATION.md │ ├── helloworld │ ├── httpbin │ ├── kubernetes-blog │ ├── rawvm │ ├── README.md │ └── sleep └── tools ├── cache_buster.yaml ├── deb ├── githubContrib ├── minikube.md ├── perf_istio_rules.yaml ├── perf_k8svcs.yaml ├── README.md ├── rules.yml ├── setup_perf_cluster.sh ├── setup_run ├── update_all └── vagrant 

從文件里表中可以看到,安裝包中包括了kubernetes的yaml文件,示例應用和安裝模板。

3.先決條件

以下說明要求您可以訪問啟用了RBAC(基於角色的訪問控制)的Kubernetes1.7.3或更新的群集。您還需要安裝1.7.3或更高版本。如果您希望啟用automatic sidecar injection,則需要Kubernetes 1.9或更高版本。kubectl

注意:如果您安裝了Istio 0.1.x,請在安裝新版本之前徹底卸載它(包括適用於所有啟用Istio的應用程序窗口的Istio支架)。 安裝或升級Kubernetes CLIkubectl以匹配群集支持的版本(CRD支持版本為1.7或更高版本)。

根據您的Kubernetes提供者:

要在本地安裝Istio,請安裝最新版本的Minikube(版本0.22.1或更高版本)。

4.安裝步驟

從0.2版本開始,Istio安裝在它自己的istio-system命名空間中,並且可以管理來自所有其他命名空間的服務。

轉至Istio發布頁面以下載與您的操作系統相對應的安裝文件。如果您使用的是MacOS或Linux系統,以下命令自動下載並提取最新版本:

curl -L https://git.io/getLatestIstio | sh - 

解壓縮安裝文件並將目錄更改為文件位置。

安裝目錄包含

Installation .yaml Kubernetes的安裝文件
Sample/ 示例應用程序
bin/istioctl 二進制bin/文件 在手動注入Envoy作為附屬代理並創建路由規則和策略時使用.
istio.VERSION配置文件

例如,如果包是istio-0.5(初步)

cd istio-0.5 (preliminary) 

將istioctl客戶端添加到您的PATH。例如,在MacOS或Linux系統上運行以下命令:

export PATH=$PWD/bin:$PATH 

安裝Istio的核心組件。從下面兩個互相排斥的選項中選擇一個,或者用Helm Chart交替安裝: a)安裝Istio而不啟用側車間的相互TLS認證。為具有現有應用程序的群集,使用Istio輔助車的服務需要能夠與其他非Istio Kubernetes服務以及使用活動性和准備就緒探測器,無頭服務或StatefulSets的應用程序通信的應用程序選擇此選項。

kubectl apply -f install/kubernetes/istio.yaml

要么

b)安裝Istio並啟用側櫃之間的相互TLS認證:

kubectl apply -f install/kubernetes/istio-auth.yaml

這兩個選項都會創建istio-system命名空間以及所需的RBAC權限,並部署Istio-Pilot,Istio-Mixer,Istio-Ingress和Istio-CA(證書頒發機構)。

可選:如果您的群集的Kubernetes版本是1.9或更高,並且您希望啟用自動代理注入,請安裝sidecar injector webhook。 驗證安裝 請確保以下Kubernetes服務部署:istio-pilot,istio-mixer,istio-ingress。

kubectl get svc -n istio-system
NAME            CLUSTER-IP      EXTERNAL-IP       PORT(S) AGE istio-ingress 10.83.245.171 35.184.245.62 80:32730/TCP,443:30574/TCP 5h istio-pilot 10.83.251.173 <none> 8080/TCP,8081/TCP 5h istio-mixer 10.83.244.253 <none> 9091/TCP,9094/TCP,42422/TCP 5h 

注意:如果您的集群中不支持外部負載平衡(例如,Minikube)的環境中運行,該external-ip的istio-ingress會顯示。您必須使用NodePort訪問應用程序,或使用端口轉發。

修改istio.yaml中的istio-ingress service的type為ClusterIP,並設置nodePort,默認為32000。

確保相應Kubernetes容器都運行起來:istio-pilot-*istio-mixer-*istio-ingress-*istio-ca-*,和可選的istio-sidecar-injector-*

kubectl get pods -n istio-system
istio-ca-3657790228-j21b9                1/1       Running   0          5h
istio-ingress-1842462111-j3vcs           1/1       Running   0          5h
istio-sidecar-injector-184129454-zdgf5   1/1       Running   0          5h
istio-pilot-2275554717-93c43             1/1       Running   0          5h
istio-mixer-2104784889-20rm8             2/2       Running   0          5h

部署您的應用程序

您現在可以部署您自己的應用程序或者像Bookinfo一樣隨安裝提供的示例應用程序之一。注意:應用程序必須對所有HTTP通信使用HTTP/1.1或HTTP/2.0協議,因為HTTP/1.0不受支持。

如果您啟動了Istio-sidecar-injector,如上所示,您可以直接使用應用程序部署應用程序kubectl create。

Istio Sidecar注入器會自動將Envoy容器注入到您的應用程序窗格中,假設運行在標有名稱空間的名稱空間中istio-injection=enabled

kubectl label namespace <namespace> istio-injection=enabled 
kubectl create -n <namspace> -f <your-app-spec>.yaml 

如果您沒有安裝Istio-sidecar-injector,則在部署它們之前,必須使用istioctl kube-inject將Envoy容器手動注入應用程序窗格中:

kubectl create -f <(istioctl kube-inject -f <your-app-spec>.yaml) 

卸載

卸載Istio sidecar進樣器:

如果您啟用Istio-sidecar-injector,請將其卸載:

kubectl delete -f install/kubernetes/istio-sidecar-injector-with-ca-bundle.yaml

卸載Istio核心組件。對於0.6(初始)發行版,卸載將刪除RBAC權限,istio-system命名空間和分層下的所有資源。忽略不存在資源的錯誤是安全的,因為它們可能已被分層刪除。

a)如果您在禁用相互TLS身份驗證的情況下安裝了Istio:

kubectl delete -f install/kubernetes/istio.yaml

要么

b)如果您在啟用相互TLS身份驗證的情況下安裝了Istio:

kubectl delete -f install/kubernetes/istio-auth.yaml

7.安裝監控插件

安裝插件

kubectl apply -f install/kubernetes/addons/prometheus.yaml
kubectl apply -f install/kubernetes/addons/grafana.yaml
kubectl apply -f install/kubernetes/addons/servicegraph.yaml
kubectl apply -f install/kubernetes/addons/zipkin.yaml

在traefik ingress中增加增加以上幾個服務的配置,同時增加istio-ingress配置。

    - host: grafana.istio.io
      http:
        paths:
        - path: /
          backend:
            serviceName: grafana
            servicePort: 3000
    - host: servicegraph.istio.io
      http:
        paths:
        - path: /
          backend:
            serviceName: servicegraph
            servicePort: 8088
    - host: prometheus.istio.io
      http:
        paths:
        - path: /
          backend:
            serviceName: prometheus
            servicePort: 9090
    - host: zipkin.istio.io
      http:
        paths:
        - path: /
          backend:
            serviceName: zipkin
            servicePort: 9411
    - host: ingress.istio.io
      http:
        paths:
        - path: /
          backend:
            serviceName: istio-ingress
            servicePort: 80

 

測試

我們使用Istio提供的測試應用bookinfo微服務來進行測試。

該微服務用到的鏡像有:

istio/examples-bookinfo-details-v1
istio/examples-bookinfo-ratings-v1
istio/examples-bookinfo-reviews-v1
istio/examples-bookinfo-reviews-v2
istio/examples-bookinfo-reviews-v3
istio/examples-bookinfo-productpage-v1

該應用架構圖如下:

BookInfo Sample應用架構圖圖片 - BookInfo Sample應用架構圖

部署應用

kubectl create -f <(istioctl kube-inject -f samples/apps/bookinfo/bookinfo.yaml)

Istio kube-inject命令會在bookinfo.yaml文件中增加Envoy sidecar信息。參考:https://istio.io/docs/reference/commands/istioctl.html#istioctl-kube-inject

在本機的/etc/hosts下增加VIP節點和ingress.istio.io的對應信息,具體步驟參考:邊緣節點配置,或者使用gateway ingress來訪問服務,

如果將productpage配置在了ingress里了,那么在瀏覽器中訪問http://ingress.istio.io/productpage,如果使用了istio默認的gateway ingress配置的話,ingress service使用nodePort方式暴露的默認使用32000端口,那么可以使用http://任意節點的IP:32000/productpage來訪問。

BookInfo Sample頁面圖片 - BookInfo Sample頁面

多次刷新頁面,你會發現有的頁面上的評論里有星級打分,有的頁面就沒有,這是因為我們部署了三個版本的應用,有的應用里包含了評分,有的沒有。Istio根據默認策略隨機將流量分配到三個版本的應用上。

查看部署的bookinfo應用中的productpage-v1 service和deployment,查看productpage-v1的pod的詳細json信息可以看到這樣的結構:

$ kubectl get pod productpage-v1-944450470-bd530 -o json

productpage-v1-istio.json文件。從詳細輸出中可以看到這個Pod中實際有兩個容器,這里面包括了initContainer,作為istio植入到kubernetes deployment中的sidecar。

"initContainers": [ { "args": [ "-p", "15001", "-u", "1337" ], "image": "docker.io/istio/init:0.1", "imagePullPolicy": "Always", "name": "init", "resources": {}, "securityContext": { "capabilities": { "add": [ "NET_ADMIN" ] } }, "terminationMessagePath": "/dev/termination-log", "terminationMessagePolicy": "File", "volumeMounts": [ { "mountPath": "/var/run/secrets/kubernetes.io/serviceaccount", "name": "default-token-3l9f0", "readOnly": true } ] }, { "args": [ "-c", "sysctl -w kernel.core_pattern=/tmp/core.%e.%p.%t \u0026\u0026 ulimit -c unlimited" ], "command": [ "/bin/sh" ], "image": "alpine", "imagePullPolicy": "Always", "name": "enable-core-dump", "resources": {}, "securityContext": { "privileged": true }, "terminationMessagePath": "/dev/termination-log", "terminationMessagePolicy": "File", "volumeMounts": [ { "mountPath": "/var/run/secrets/kubernetes.io/serviceaccount", "name": "default-token-3l9f0", "readOnly": true } ] } ], 

監控

不斷刷新productpage頁面,將可以在以下幾個監控中看到如下界面。

Grafana頁面

http://grafana.istio.io

Istio Grafana界面圖片 - Istio Grafana界面

Prometheus頁面

http://prometheus.istio.io

Prometheus頁面圖片 - Prometheus頁面

Zipkin頁面

http://zipkin.istio.io

Zipkin頁面圖片 - Zipkin頁面

ServiceGraph頁面

http://servicegraph.istio.io/dotviz

可以用來查看服務間的依賴關系。

訪問 http://servicegraph.istio.io/graph 可以獲得json格式的返回結果。

ServiceGraph頁面圖片 - ServiceGraph頁面


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM