在docker desktop的k8s中部署Istio-demo

轉(zhuǎn)載請注明出處即可
所使用的環(huán)境為macos


零、安裝前準備

docker desktop k8s安裝


一兄猩、下載istio

https://github.com/istio/istio/releases

istio下載

下載解壓后, 設(shè)置path,以下path需要換為istio的解壓后的路徑

ISTIO_PATH=/istio/istio-1.5.2
export PATH=$ISTIO_PATH/bin:$PATH

建議設(shè)置別名

alias ic=istioctl

二、開始部署isito

查看profiles list

$ ic profile list
Istio configuration profiles:
    empty
    minimal
    remote
    separate
    default
    demo

cd ${ISTIO_PATH}/install/kubernetes/operator/profiles 目錄下可以看到profiles的具體配置, 打開demo.yaml

demo.yaml

因為是demo部署码泛,所以將大部分組件全部部署了,并增加了cpu和memory的限制

在這里跑個題, 在生產(chǎn)環(huán)境部署幾乎不會完全使用官方的配置澄耍,雖然default是官方推薦的生產(chǎn)環(huán)境的基本配置弟晚。以下是使用自己的配置文件進行部署,不用profile

ic manifest apply -f default.yaml --set values.global.jwtPolicy=first-party-jwt

使用profile=demo進行部署

ic manifest apply --set profile=demo

等待部署結(jié)束即可, 會下載相關(guān)的docker image


部署istio

部署完成


部署完成

如果要刪除istio的部署

istioctl manifest generate --set profile=demo | kubectl delete -f -

查看k8s的namespace, 發(fā)現(xiàn)新增一個istio-system

$ k get namespaces
NAME              STATUS   AGE
default           Active   6h2m
docker            Active   6h1m
istio-system      Active   3m27s
kube-node-lease   Active   6h2m
kube-public       Active   6h2m
kube-system       Active   6h2m

查看pods, 可以發(fā)現(xiàn)主要的pod已經(jīng)運行成功逾苫,其他的pod等待一會下載完docker image即可卿城。

$ k -n istio-system get po
NAME                                    READY   STATUS              RESTARTS   AGE
grafana-5cc7f86765-d655t                0/1     ContainerCreating   0          2m2s
istio-egressgateway-598d7ffc49-w585j    1/1     Running             0          2m4s
istio-ingressgateway-7bd5586b79-qlptv   1/1     Running             0          2m4s
istio-tracing-8584b4d7f9-226v8          0/1     Running             0          2m2s
istiod-646b6fcc6-rkdkf                  1/1     Running             0          4m
kiali-696bb665-tsfsv                    0/1     ContainerCreating   0          2m2s
prometheus-6c88c4cb8-kjx2j              0/2     ContainerCreating   0          2m2s

如果出現(xiàn)了status為ImagePullBackOff,這個沒有關(guān)系铅搓,k8s還會再次去pull image瑟押。
當然也可以手動pull image。比如以下pod部署失敗

kiali-696bb665-tsfsv                    0/1     ImagePullBackOff   0          10m

查看pod的詳情

k -n istio-system describe po kiali-696bb665-tsfsv
pod詳情

找到下面圖中的image手動pull星掰,或者找到國內(nèi)的mirror pull多望,在tag成quay.io的。

在等待過程中氢烘,我們可以檢查下istio的部署情況

$ ic analyze
Warn [IST0102] (Namespace default) The namespace is not enabled for Istio injection. Run 'kubectl label namespace default istio-injection=enabled' to enable it, or 'kubectl label namespace default istio-injection=disabled' to explicitly mark it as not needing injection
Error: Analyzers found issues when analyzing namespace: default.
See https://istio.io/docs/reference/config/analysis for more information about causes and resolutions.

可以看到如果要在某個k8s的namespace中默認在部署pod時怀偷,部署istio的數(shù)據(jù)平面,需要給對應的namespace增加istio-injection=enabled的label播玖。

創(chuàng)建一個新的namespace

k create namespace ic-test

并增加istio注入的label

kubectl label namespace ic-test istio-injection=enabled

三椎工、部署3個demo服務

部署的是https://github.com/cloudnativebooks/cloud-native-istio
下在weather-v1.yaml,但版本有些老了蜀踏,api不太一樣维蒙。

將以下內(nèi)容保存在demo.yaml中

apiVersion: v1
kind: Service
metadata:
  name: frontend
  labels:
    app: frontend
    service: frontend
spec:
  ports:
  - port: 3000
    name: http
  selector:
    app: frontend
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend-v1
  labels:
    app: frontend
    version: v1
spec:
  selector:
    matchLabels:
      app: frontend
      version: v1
  replicas: 1
  template:
    metadata:
      labels:
        app: frontend
        version: v1
    spec:
      containers:
      - name: frontend
        image: istioweather/frontend:v1
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
  name: advertisement
  labels:
    app: advertisement
    service: advertisement
spec:
  ports:
  - port: 3003
    name: http
  selector:
    app: advertisement
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: advertisement-v1
  labels:
    app: advertisement
    version: v1
spec:
  selector:
    matchLabels:
      app: advertisement
      version: v1
  replicas: 1
  template:
    metadata:
      labels:
        app: advertisement
        version: v1
    spec:
      containers:
      - name: advertisement
        image: istioweather/advertisement:v1
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3003
---
apiVersion: v1
kind: Service
metadata:
  name: forecast
  labels:
    app: forecast
    service: forecast
spec:
  ports:
  - port: 3002
    name: http
  selector:
    app: forecast
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: forecast-v1
  labels:
    app: forecast
    version: v1
spec:
  selector:
    matchLabels:
      app: forecast
      version: v1
  replicas: 1
  template:
    metadata:
      labels:
        app: forecast
        version: v1
    spec:
      containers:
      - name: forecast
        image: istioweather/forecast:v1
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3002
---

開始部署

$ k -n ic-test apply -f demo.yaml
service/frontend created
deployment.apps/frontend-v1 created
service/advertisement created
deployment.apps/advertisement-v1 created
service/forecast created
deployment.apps/forecast-v1 created

查看pods,如果部署成功的化果覆,會有以下三個pods颅痊,在Running狀態(tài)

$ k -n ic-test get po
NAME                                READY   STATUS    RESTARTS   AGE
advertisement-v1-68d74cc5bd-9wsdl   2/2     Running   0          2m22s
forecast-v1-77dcd878bc-ckwr5        2/2     Running   0          2m22s
frontend-v1-75d4648dc6-hplwf        2/2     Running   0          2m22s

部署gateway,將以下內(nèi)容保存到gateway.yaml中

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: weather-gateway
  namespace: istio-system
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: frontend-dr
  namespace: ic-test
spec:
  host: frontend
  subsets:
  - name: v1
    labels:
      version: v1
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: frontend-route
  namespace: ic-test
spec:
  hosts:
  - "*"
  gateways:
  - istio-system/weather-gateway
  http:
  - match:
    - port: 80
    route:
    - destination:
        host: frontend
        port:
          number: 3000
        subset: v1

部署gateway, 部署前先檢查80端口是否被占用

$ k apply -f weather-gateway.yaml
gateway.networking.istio.io/weather-gateway created
destinationrule.networking.istio.io/frontend-dr created
virtualservice.networking.istio.io/frontend-route created

瀏覽器中打開 http://localhost/dashboard

部署的服務


四局待、使用kiali等組件

創(chuàng)建kiali-secret.yaml, 添加如下內(nèi)容

apiVersion: v1
kind: Secret
metadata:
  name: kiali
  namespace: istio-system
  labels:
    app: kiali
type: Opaque
data:
  username: YWRtaW4=
  passphrase: YWRtaW4=

創(chuàng)建Secret

k apply -f kiali-secret.yaml

設(shè)置組件的訪問方式, 保存為access.yaml

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: grafana-gateway
  namespace: istio-system
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 15031
      name: http-grafana
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: grafana-vs
  namespace: istio-system
spec:
  hosts:
  - "*"
  gateways:
  - grafana-gateway
  http:
  - match:
    - port: 15031
    route:
    - destination:
        host: grafana
        port:
          number: 3000
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: grafana
  namespace: istio-system
spec:
  host: grafana
  trafficPolicy:
    tls:
      mode: DISABLE
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: kiali-gateway
  namespace: istio-system
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 15029
      name: http-kiali
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: kiali-vs
  namespace: istio-system
spec:
  hosts:
  - "*"
  gateways:
  - kiali-gateway
  http:
  - match:
    - port: 15029
    route:
    - destination:
        host: kiali
        port:
          number: 20001
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: kiali
  namespace: istio-system
spec:
  host: kiali
  trafficPolicy:
    tls:
      mode: DISABLE
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: prometheus-gateway
  namespace: istio-system
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 15030
      name: http-prom
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: prometheus-vs
  namespace: istio-system
spec:
  hosts:
  - "*"
  gateways:
  - prometheus-gateway
  http:
  - match:
    - port: 15030
    route:
    - destination:
        host: prometheus
        port:
          number: 9090
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: prometheus
  namespace: istio-system
spec:
  host: prometheus
  trafficPolicy:
    tls:
      mode: DISABLE
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: tracing-gateway
  namespace: istio-system
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 15032
      name: http-tracing
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: tracing-vs
  namespace: istio-system
spec:
  hosts:
  - "*"
  gateways:
  - tracing-gateway
  http:
  - match:
    - port: 15032
    route:
    - destination:
        host: tracing
        port:
          number: 80
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: tracing
  namespace: istio-system
spec:
  host: tracing
  trafficPolicy:
    tls:
      mode: DISABLE

添加Gateway規(guī)則

$ k apply -f access.yaml
gateway.networking.istio.io/grafana-gateway created
virtualservice.networking.istio.io/grafana-vs created
destinationrule.networking.istio.io/grafana created
gateway.networking.istio.io/kiali-gateway created
virtualservice.networking.istio.io/kiali-vs created
destinationrule.networking.istio.io/kiali created
gateway.networking.istio.io/prometheus-gateway created
virtualservice.networking.istio.io/prometheus-vs created
destinationrule.networking.istio.io/prometheus created
gateway.networking.istio.io/tracing-gateway created
virtualservice.networking.istio.io/tracing-vs created
destinationrule.networking.istio.io/tracing created

訪問kiali

http://localhost:15029/kiali/
前面設(shè)置的secret斑响,用戶名和密碼都是admin

kiali

在Graph中的namespace選擇ic-test,可以看到當前的調(diào)用鏈路
kiali

訪問jaeger ui

http://localhost:15032/jaeger
點擊Find Traces可以看到右側(cè)的調(diào)用鏈路

jaeger ui

訪問Grafana

http://localhost:15031/?orgId=1

Grafana

Grafana istio

istio pilot的監(jiān)控信息

導入1471的dashboard


import

選擇prometheus

查看監(jiān)控

參考

《云原生服務網(wǎng)格Istio》

https://istio.io/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末钳榨,一起剝皮案震驚了整個濱河市舰罚,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌重绷,老刑警劉巖沸停,帶你破解...
    沈念sama閱讀 217,509評論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件膜毁,死亡現(xiàn)場離奇詭異昭卓,居然都是意外死亡愤钾,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,806評論 3 394
  • 文/潘曉璐 我一進店門候醒,熙熙樓的掌柜王于貴愁眉苦臉地迎上來能颁,“玉大人,你說我怎么就攤上這事倒淫』锞眨” “怎么了?”我有些...
    開封第一講書人閱讀 163,875評論 0 354
  • 文/不壞的土叔 我叫張陵敌土,是天一觀的道長镜硕。 經(jīng)常有香客問我,道長返干,這世上最難降的妖魔是什么兴枯? 我笑而不...
    開封第一講書人閱讀 58,441評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮矩欠,結(jié)果婚禮上财剖,老公的妹妹穿的比我還像新娘。我一直安慰自己癌淮,他們只是感情好躺坟,可當我...
    茶點故事閱讀 67,488評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著乳蓄,像睡著了一般咪橙。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上虚倒,一...
    開封第一講書人閱讀 51,365評論 1 302
  • 那天匣摘,我揣著相機與錄音,去河邊找鬼裹刮。 笑死音榜,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的捧弃。 我是一名探鬼主播赠叼,決...
    沈念sama閱讀 40,190評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼鸣哀,長吁一口氣:“原來是場噩夢啊……” “哼彪杉!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起乾巧,我...
    開封第一講書人閱讀 39,062評論 0 276
  • 序言:老撾萬榮一對情侶失蹤买鸽,失蹤者是張志新(化名)和其女友劉穎涧郊,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體眼五,經(jīng)...
    沈念sama閱讀 45,500評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡妆艘,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,706評論 3 335
  • 正文 我和宋清朗相戀三年彤灶,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片批旺。...
    茶點故事閱讀 39,834評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡幌陕,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出汽煮,到底是詐尸還是另有隱情搏熄,我是刑警寧澤,帶...
    沈念sama閱讀 35,559評論 5 345
  • 正文 年R本政府宣布暇赤,位于F島的核電站心例,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏鞋囊。R本人自食惡果不足惜契邀,卻給世界環(huán)境...
    茶點故事閱讀 41,167評論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望失暴。 院中可真熱鬧坯门,春花似錦、人聲如沸逗扒。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,779評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽矩肩。三九已至现恼,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間黍檩,已是汗流浹背叉袍。 一陣腳步聲響...
    開封第一講書人閱讀 32,912評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留刽酱,地道東北人喳逛。 一個月前我還...
    沈念sama閱讀 47,958評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像棵里,于是被迫代替她去往敵國和親润文。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,779評論 2 354

推薦閱讀更多精彩內(nèi)容