快速上手
1. docker desktop 上安装istio
这里采用docker desktop安装。如果没有安装docker desktop 看这里 docker desktop 安装
我们安装21年1.9 release 版本。
这里告诉你其他的安装方式,你可以根据场景选择。=>其他安装istio 方式
这里使用这种方式 Install with Istioctl Install with Istioctl
安装事先准备
- 根据你的环境下载对应的istioctl istio
-
设置好平台 docker desktop
至少需要分配4个CPU,8个G内存
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-iWCx4JrK-1613806927847)(http://andtwo.vip/wp-content/uploads/2021/02/docker_desktop.png)]
- 检查已运行的pods 与 service
- 服务关系:一个Pod必须至少属于一个Kubernetes服务,即使Pod不暴露任何端口也是如此。如果Pod属于多个Kubernetes服务,则这些服务不能将相同的端口号用于不同的协议,例如HTTP和TCP
- 应用UID:确保Pod不以用户ID(UID)为1337的用户身份运行应用程序
- 有NET_ADMIN NET_RAW 的能力
- 带有应用和版本标签的部署
- 命名服务端口:服务端口必须命名。端口名称键/值对必须具有以下语法
name: <protocol>[-<suffix>]
安装istio
>istioctl install
Detected that your cluster does not support third party JWT authentication. Falling back to less secure first party JWT. See https://istio.io/v1.9/docs/ops/best-practices/security/#configure-third-party-service-account-tokens for details.
This will install the Istio 1.9.0 profile with ["Istio core" "Istiod" "Ingress gateways"] components into the cluster. Proceed? (y/N) y
✔ Istio core installed
✔ Istiod installed
✔ Ingress gateways installed
- Pruning removed resources Removed PodDisruptionBudget:istio-system:istio-egressgateway.
Removed Deployment:istio-system:istio-egressgateway.
Removed Service:istio-system:istio-egressgateway.
Removed ServiceAccount:istio-system:istio-egressgateway-service-account.
Removed RoleBinding:istio-system:istio-egressgateway-sds.
Removed Role:istio-system:istio-egressgateway-sds.
✔ Installation complete
2. istio 中部署一个应用
- git clone 书上的列子:
git clone https://github.com/osswangxining/istio-book
- 创建命名空间 voting,
kubectl create ns voting
- 为命名空间增加一个标签 istio-injection=enabled ,四体哦自动将代理sidecar 注入到此命名空间下的所有pod中
kubectl label ns voting istio-injection=enabled
-
应用pod,部署1.0版本
在 istio-book/intelligent-routing-with-istio 目录下
输出以下,表示成功创建:kubectl apply -f kubernetes/step-1-create-voting-app.yaml --namespace voting
>kubectl apply -f kubernetes/step-1-create-voting-app.yaml --namespace voting
deployment.apps/voting-storage-1-0 created
service/voting-storage created
deployment.apps/voting-analytics-1-0 created
service/voting-analytics created
deployment.apps/voting-app-1-0 created
service/voting-app created
过一会检查下pods是否正常在跑
>kubectl get pods -n voting
NAME READY STATUS RESTARTS AGE
voting-analytics-1-0-7d679cdb57-hmswv 2/2 Running 0 6m58s
voting-app-1-0-848ddcfd4c-shxks 2/2 Running 0 6m57s
voting-storage-1-0-7c76cb7d47-mfvqw 2/2 Running 0 6m58s
- 创建网关
>kubectl apply -f istio/step-1-create-voting-app-gateway.yaml --namespace voting
virtualservice.networking.istio.io/voting-app created
gateway.networking.istio.io/voting-app-gateway created
- 检查service 状态
>kubectl get svc -n voting
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
voting-analytics ClusterIP 10.99.104.100 <none> 8080/TCP 12m
voting-app ClusterIP 10.96.173.223 <none> 8080/TCP 12m
voting-storage ClusterIP 10.97.231.62 <none> 6379/TCP 12m
下面命令查看istio Gateway =》voting-app-gateway
kubectl get gateway
下面命令查看虚拟服务
kubectl get vs -n voting
NAME GATEWAYS HOSTS AGE
voting-app [voting-app-gateway] [*] 30m
-
页面验证
页面访问一下http://localhost 出现以下页面,表示运行成功 (点击istio 会累加,其他时也会累加)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-A5ZEc4qW-1613806927852)(http://andtwo.vip/wp-content/uploads/2021/02/截屏2021-02-20-下午2.52.56.png)]
-
部署2.0 版本
2.0 版本增加了cookie featureflag=on 匹配规则,命中了会走v2版本
kubectl apply -f istio/step-2a-update-voting-app-virtualservice.yaml --namespace voting
更新虚拟服务/目标规则
>kubectl apply -f istio/step-2b-add-routing-for-all-components.yaml -n voting
destinationrule.networking.istio.io/voting-app created
destinationrule.networking.istio.io/voting-analytics created
virtualservice.networking.istio.io/voting-analytics created
destinationrule.networking.istio.io/voting-storage created
virtualservice.networking.istio.io/voting-storage created
更新voting-app服务,增加v2版本
kubectl apply -f kubernetes/step-2-update-voting-app-to-2.0.yaml -n voting
检查下:
>kubectl get pods -n voting
NAME READY STATUS RESTARTS AGE
voting-analytics-1-0-7d679cdb57-hmswv 2/2 Running 0 61m
voting-app-1-0-848ddcfd4c-shxks 2/2 Running 0 61m
voting-app-2-0-5686d959cb-wj7dg 2/2 Running 0 56s
voting-storage-1-0-7c76cb7d47-mfvqw 2/2 Running 0 61m
>kubectl get vs -n voting
NAME GATEWAYS HOSTS AGE
voting-analytics [voting-analytics.voting.svc.cluster.local] 6m15s
voting-app [voting-app-gateway] [*] 63m
voting-storage [voting-storage.voting.svc.cluster.local] 6m15s
-
检查V2版本
再次打开http://localhost,图中set 点击一次,会在cookie中增加v2版本的标示,页面会刷新成v2的样子。v2版本没有下方的灰色内容
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5EX3YHdz-1613806927854)(http://andtwo.vip/wp-content/uploads/2021/02/v1.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fwMPQaid-1613806927856)(http://andtwo.vip/wp-content/uploads/2021/02/v2.png)]
到此,初次的istio 使用实践完成。
这里具体gateway ,virtualservice,destinationRule,policy 等后续文章会具体介绍。
图片没有的,请移步个人网站 andtwo.vip