K8S集群部署istio


簡介

Istio 提供一種簡單的方式來為已部署的服務建立網絡,該網絡具有負載均衡、服務間認證、監控等功能,而不需要對服務的代碼做任何改動。

istio 適用於容器或虛擬機環境(特別是 k8s),兼容異構架構。

istio 使用 sidecar(邊車模式)代理服務的網絡,不需要對業務代碼本身做任何的改動。

HTTP、gRPC、WebSocket 和 TCP 流量的自動負載均衡。

istio 通過豐富的路由規則、重試、故障轉移和故障注入,可以對流量行為進行細粒度控制;支持訪問控制、速率限制和配額。

istio 對出入集群入口和出口中所有流量的自動度量指標、日志記錄和跟蹤。

對比國內阿里雲和K8S官方維護的Nginx Ingress Controller及 Istio Gateway 比較

  Istio Gateway 阿里雲Ingress Controller NGINX Ingress Controller
根據HTTP Header選擇路由規則 支持 支持 僅支持單個Header,不支持多個Header組合
Header規則支持正則表達式 支持 支持 支持
服務之間設置權重拆分流量 支持 支持 支持
Header和權重規則組合使用 支持 支持 支持
路由規則檢查 支持 不支持 不支持
路由規則粒度 service下的不同pod service service
支持的協議 HTTP1.1/HTTP2/gRPC/TCP/Websockets/MongoDB HTTP1.1/HTTP2/gRPC/TCP/Websockets HTTP1.1/HTTP2/gRPC/TCP/Websockets

 

 部署istio

1、下載istio官方的部署包網址:https://github.com/istio/istio/releases/tag/1.6.7
wget https://github.com/istio/istio/releases/download/1.6.7/istio-1.6.7-linux-amd64.tar.gz
2、解壓安裝包並加入環境變量中
mkdir /application/
tar xvf istio-1.6.7-linux-amd64.tar.gz -C /application /
echo "export PATH=$PATH:/application/istio-1.6.7/bin" >>/etc/profile && source /etc/profile
3、安裝istio(ps:一定要保證k8s集群正常運行)
[root@k8s-master ~]# kubectl get nodes
NAME         STATUS   ROLES    AGE    VERSION
k8s-master   Ready    master   7d2h   v1.18.0
node-1       Ready    <none>   7d2h   v1.18.0
node-2       Ready    <none>   7d2h   v1.18.0
[root@k8s-master ~]# 
4、安裝
[root@k8s-master bin]# istioctl manifest apply --set profile=demo
Detected that your cluster does not support third party JWT authentication. Falling back to less secure first party JWT. See https://istio.io/docs/ops/best-practices/security/#configure-third-party-service-account-tokens for details.
✔ Istio core installed
✔ Istiod installed
✔ Ingress gateways installed
✔ Egress gateways installed
✔ Addons installed
✔ Installation complete
[root@k8s-master bin]#

查詢部署完成情況

[root@k8s-master bin]# kubectl get svc -n istio-system
NAME                        TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                                                                      AGE
grafana                     ClusterIP      10.100.91.88     <none>        3000/TCP                                                                     2m5s
istio-egressgateway         ClusterIP      10.106.229.1     <none>        80/TCP,443/TCP,15443/TCP                                                     2m6s
istio-ingressgateway        LoadBalancer   10.111.48.40     <pending>     15021:30045/TCP,80:31929/TCP,443:31560/TCP,31400:31134/TCP,15443:31166/TCP   2m6s
istiod                      ClusterIP      10.101.173.49    <none>        15010/TCP,15012/TCP,443/TCP,15014/TCP,853/TCP                                2m30s
jaeger-agent                ClusterIP      None             <none>        5775/UDP,6831/UDP,6832/UDP                                                   2m5s
jaeger-collector            ClusterIP      10.103.41.41     <none>        14267/TCP,14268/TCP,14250/TCP                                                2m5s
jaeger-collector-headless   ClusterIP      None             <none>        14250/TCP                                                                    2m5s
jaeger-query                ClusterIP      10.97.12.213     <none>        16686/TCP                                                                    2m5s
kiali                       ClusterIP      10.105.102.92    <none>        20001/TCP                                                                    2m5s
prometheus                  ClusterIP      10.98.88.198     <none>        9090/TCP                                                                     2m5s
tracing                     ClusterIP      10.97.49.170     <none>        80/TCP                                                                       2m5s
zipkin                      ClusterIP      10.111.114.233   <none>        9411/TCP                                                                     2m5s
[root@k8s-master bin]# kubectl get pods -n istio-system
NAME                                    READY   STATUS    RESTARTS   AGE
grafana-b54bb57b9-4ncvl                 1/1     Running   0          2m28s
istio-egressgateway-64bc874f5c-bxqb8    1/1     Running   0          2m29s
istio-ingressgateway-6b947b8c5d-xdttt   1/1     Running   0          2m29s
istio-tracing-9dd6c4f7c-vljvl           1/1     Running   0          2m28s
istiod-654b4b468b-lfhgf                 1/1     Running   0          2m54s
kiali-d45468dc4-q6wbn                   1/1     Running   0          2m28s
prometheus-77566c9987-285jt             2/2     Running   0          2m28s
[root@k8s-master bin]#

設置可視化界面kiali為外部訪問模式並查詢nodeport號

[root@k8s-master bin]# kubectl patch svc -n istio-system kiali -p '{"spec": {"type": "NodePort"}}'
service/kiali patched
[root@k8s-master bin]# kubectl describe svc -n istio-system kiali
Name:                     kiali
Namespace:                istio-system
Labels:                   app=kiali
                          install.operator.istio.io/owning-resource=installed-state
                          install.operator.istio.io/owning-resource-namespace=istio-system
                          operator.istio.io/component=AddonComponents
                          operator.istio.io/managed=Reconcile
                          operator.istio.io/version=1.6.7
                          release=istio
Annotations:              Selector:  app=kiali
Type:                     NodePort
IP:                       10.105.102.92
Port:                     http-kiali  20001/TCP
TargetPort:               20001/TCP
NodePort:                 http-kiali  31822/TCP  #節點訪問的端口
Endpoints:                10.244.247.6:20001
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>
[root@k8s-master bin]#

訪問node節點加上端口 192.168.10.112:31822 

 默認登陸賬戶和密碼為admin/admin

istio上部署測試應用bookinfo

1、開啟sidecar自動注入
kubectl label namespace default istio-injection=enabled
2、使用kubectl部署bookinfo並創建網關
kubectl apply -f /application/istio-1.6.7/samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f /application/istio-1.6.7/samples/bookinfo/networking/bookinfo-gateway.yaml 
3、設置訪問網關的 INGRESS_HOST 和 INGRESS_PORT 變量,查詢是否有外部負載均衡器
kubectl get svc istio-ingressgateway -n istio-system
EXTERNAL-IP是none或是pending說明沒有問題

修改istio的網關為nodeport模式 

kubectl patch service istio-ingressgateway -n istio-system -p '{"spec":{"type":"NodePort"}}'

采用nodeport方式暴露istio-ingressgateway

export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}')
#獲取 ingress IP 地址:
export INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o 'jsonpath={.items[0].status.hostIP}')

查詢URL

echo $INGRESS_HOST:$INGRESS_PORT
192.168.10.112:30637

使用瀏覽器訪問bookinfo

http://192.168.10.112:30637/productpage

 重復刷新可以發現星星發生變化說明部署成功

參考地址:
https://blog.csdn.net/weixin_44144334/article/details/107788292
https://developer.aliyun.com/article/636511

如有侵權請及時聯系刪除


免責聲明!

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



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