Service Mesh - Istio安裝與部署

安裝與部署:如何安裝Istio?它都支持哪些環境和部署方式?

首先,咱們須要準備一個Kubernetes環境:node

下載Istio

在當前版本Istio的安裝與部署已經變得很是簡單了,只須要幾個簡單的步驟就能將Istio環境搭建起來。首先要作的是下載Istio(在文檔中核對Istio支持的k8s版本):json

獲取下載腳本並執行:vim

[root@m1 ~]# curl -L https://istio.io/downloadIstio | sh -

將下載好的istio目錄移動到合適的位置下:api

[root@m1 ~]# mv istio-1.8.1/ /usr/local

配置環境變量:瀏覽器

[root@m1 ~]# vim /etc/profile
export ISTIO_HOME=/usr/local/istio-1.8.1
export PATH=$PATH:$ISTIO_HOME/bin
[root@m1 ~]# source /etc/profile

驗證 istioctl 命令是否可正常工做:bash

[root@m1 ~]# istioctl version
no running Istio pods in "istio-system"
1.8.1
[root@m1 ~]#

安裝Istio

配置檔案(configuration profile):
Service Mesh - Istio安裝與部署app

  • 安裝時選擇不一樣的 profile 會安裝不一樣的組件,官方文檔

使用 istioctl 的安裝方式:curl

安裝方式 示例
默認安裝 istioctl manifest apply
選擇profile istioctl manifest apply --set profile=demo
自定義安裝選項 istioctl manifest apply --set addonComponents.grafana.enabled=true
自定義安裝清單 istioctl manifest apply --set installPackagePath=<發佈路徑>/install/kubernetes/operator/charts

在學習、實驗環境咱們能夠選擇 demo 這個 profile 進行安裝,以下示例:ide

[root@m1 ~]# istioctl install --set profile=demo -y
✔ Istio core installed
✔ Istiod installed
✔ Egress gateways installed
✔ Ingress gateways installed
✔ Installation complete
[root@m1 ~]#

查看istio相應的 namespace 和 pod 是否已經正常建立:oop

[root@m1 ~]# kubectl get ns |grep istio
istio-system           Active   7m10s
[root@m1 ~]# kubectl get pods -n istio-system
NAME                                    READY   STATUS    RESTARTS   AGE
istio-egressgateway-d84f95b69-dmpzf     1/1     Running   0          6m28s
istio-ingressgateway-75f6d79f48-5lr5b   1/1     Running   0          6m28s
istiod-c9f6864c4-5kjz7                  1/1     Running   0          7m50s
[root@m1 ~]#

檢查 istio 的 CRD 和 API 資源:

[root@m1 ~]# kubectl get crd |grep istio
authorizationpolicies.security.istio.io               2020-12-21T02:53:41Z
destinationrules.networking.istio.io                  2020-12-21T02:53:41Z
envoyfilters.networking.istio.io                      2020-12-21T02:53:41Z
gateways.networking.istio.io                          2020-12-21T02:53:41Z
istiooperators.install.istio.io                       2020-12-21T02:53:41Z
peerauthentications.security.istio.io                 2020-12-21T02:53:41Z
requestauthentications.security.istio.io              2020-12-21T02:53:41Z
serviceentries.networking.istio.io                    2020-12-21T02:53:41Z
sidecars.networking.istio.io                          2020-12-21T02:53:41Z
virtualservices.networking.istio.io                   2020-12-21T02:53:41Z
workloadentries.networking.istio.io                   2020-12-21T02:53:41Z
workloadgroups.networking.istio.io                    2020-12-21T02:53:41Z
[root@m1 ~]# kubectl api-resources |grep istio
istiooperators                 iop,io       install.istio.io               true         IstioOperator
destinationrules               dr           networking.istio.io            true         DestinationRule
envoyfilters                                networking.istio.io            true         EnvoyFilter
gateways                       gw           networking.istio.io            true         Gateway
serviceentries                 se           networking.istio.io            true         ServiceEntry
sidecars                                    networking.istio.io            true         Sidecar
virtualservices                vs           networking.istio.io            true         VirtualService
workloadentries                we           networking.istio.io            true         WorkloadEntry
workloadgroups                 wg           networking.istio.io            true         WorkloadGroup
authorizationpolicies                       security.istio.io              true         AuthorizationPolicy
peerauthentications            pa           security.istio.io              true         PeerAuthentication
requestauthentications         ra           security.istio.io              true         RequestAuthentication
[root@m1 ~]#

添加一個命名空間標籤,讓Istio在以後部署應用程序時自動注入 Envoy 的 SideCar 代理:

[root@m1 ~]# kubectl label namespace default istio-injection=enabled
namespace/default labeled
[root@m1 ~]#

安裝 dashboard 組件。命令以下:

[root@m1 ~]# kubectl apply -f /usr/local/istio-1.8.1/samples/addons -n istio-system

啓用 kiali 做爲 istio 的 dashboard:

[root@m1 ~]# istioctl dashboard kiali --address 192.168.243.138 -p 20001
http://localhost:20001/kiali

使用瀏覽器訪問:
Service Mesh - Istio安裝與部署

在 「Application」 頁面能夠查看 istio 組件信息:
Service Mesh - Istio安裝與部署

部署 Bookinfo 應用

接下來咱們部署官方提供的 demo應用 來驗證 istio 的功能:
Service Mesh - Istio安裝與部署

部署命令以下:

[root@m1 ~]# kubectl apply -f /usr/local/istio-1.8.1/samples/bookinfo/platform/kube/bookinfo.yaml
service/details created
serviceaccount/bookinfo-details created
deployment.apps/details-v1 created
service/ratings created
serviceaccount/bookinfo-ratings created
deployment.apps/ratings-v1 created
service/reviews created
serviceaccount/bookinfo-reviews created
deployment.apps/reviews-v1 created
deployment.apps/reviews-v2 created
deployment.apps/reviews-v3 created
service/productpage created
serviceaccount/bookinfo-productpage created
deployment.apps/productpage-v1 created
[root@m1 ~]#

確認服務、Pod 已啓動:

[root@m1 ~]# kubectl get pods
NAME                              READY   STATUS    RESTARTS   AGE
details-v1-79c697d759-qmtpn       2/2     Running   0          19m
productpage-v1-65576bb7bf-wqt7v   2/2     Running   0          19m
ratings-v1-7d99676f7f-jhcv6       2/2     Running   0          19m
reviews-v1-987d495c-4jlcv         2/2     Running   0          19m
reviews-v2-6c5bf657cf-n7hmw       2/2     Running   0          19m
reviews-v3-5f7b9f4f77-fpcvc       2/2     Running   0          19m
[root@m1 ~]# kubectl get svc
NAME          TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
details       ClusterIP   10.102.20.100    <none>        9080/TCP   20m
kubernetes    ClusterIP   10.96.0.1        <none>        443/TCP    112d
productpage   ClusterIP   10.97.68.248     <none>        9080/TCP   20m
ratings       ClusterIP   10.109.205.171   <none>        9080/TCP   20m
reviews       ClusterIP   10.108.11.178    <none>        9080/TCP   20m
[root@m1 ~]#

建立 Ingress 網關,不然外部沒法訪問該服務:

[root@m1 ~]# kubectl apply -f /usr/local/istio-1.8.1/samples/bookinfo/networking/bookinfo-gateway.yaml
gateway.networking.istio.io/bookinfo-gateway created
virtualservice.networking.istio.io/bookinfo created
[root@m1 ~]#

確認網關和訪問地址:

[root@m1 ~]# kubectl get gateways.networking.istio.io 
NAME               AGE
bookinfo-gateway   1m
[root@m1 ~]# kubectl get virtualservices.networking.istio.io 
NAME       GATEWAYS               HOSTS   AGE
bookinfo   ["bookinfo-gateway"]   ["*"]   1m
[root@m1 ~]# kubectl get svc -n istio-system 
NAME                   TYPE            CLUSTER-IP      EXTERNAL-IP                         AGE
istio-ingressgateway   LoadBalancer   10.111.237.225   <pending>     15021:32730/TCP,80:30383/TCP,443:30555/TCP,31400:30963/TCP,15443:32634/TCP   4h5m
[root@m1 ~]#

根據官方文檔的描述,當 istio-ingressgateway 服務的 EXTERNAL-IPpending 時,須要經過以下方式獲取訪問地址和端口號:

[root@m1 ~]# kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items[0].status.hostIP}'
192.168.243.140
[root@m1 ~]# kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}'
30383

而後就能夠使用瀏覽器訪問應用頁面了:
Service Mesh - Istio安裝與部署

此時嘗試多刷新幾回頁面,能夠發現請求會被輪詢到不一樣版本的 reviews 服務上:
Service Mesh - Istio安裝與部署
Service Mesh - Istio安裝與部署

相關文章
相關標籤/搜索