istio 部署

148 篇文章 2 订阅
10 篇文章 0 订阅

环境:kubernetes v1.11.5,istio 1.3.2,centos7

安装部署

1、 github 下载 istio1.3.2 版本,解压到 istio-1.3.2

2、创建 namespace istio-system

[root@k8s01 istio-1.3.2]# kb create ns istio-system

3、创建 crd

[root@k8s01 istio-1.3.2]# helm template install/kubernetes/helm/istio-init/ --name istio-init --namespace istio-system | kubectl apply -f -
configmap/istio-crd-10 created
configmap/istio-crd-11 created
...

4、确认所有的 crd 都创建好了,总共 23 个

[root@k8s01 istio-1.3.2]# kb get  crds  | grep 'istio.io' | wc -l
23

5、选择一个配置文件,部署 istio.

istio 默认使用 LoadBalancer ,一般公有云会支持 LoadBalancer。如果没有 LoadBalancer,可以使用 NodePort ,需要部署的时候添加 --set gateways.istio-ingressgateway.type=NodePort。

  • default 部署,可用于 production
[root@k8s01 istio-1.3.2]# helm template install/kubernetes/helm/istio --name istio --namespace istio-system --set gateways.istio-ingressgateway.type=NodePort | kubectl apply -f - 
poddisruptionbudget.policy/istio-galley created
poddisruptionbudget.policy/istio-ingressgateway created
...
  • demo 部署

保证下面参数

grafana.enabled: true # 安装 grafana 插件
tracing.enabled: true # 安装 Jaeger 插件
kiali.enabled: true   # 安装 Kiali 插件
gateways.istio-ingressgateway.type: NodePort # 可以选择的修改为 LoadBalancer, Cluster IP 或者 LoadBakancer
global.disablePolicyChecks: false # 启用检查策略

修改 install/kubernetes/helm/istio/values-istio-demo.yaml

global:
  proxy:
    accessLogFile: "/dev/stdout"
    resources:
      requests:
        cpu: 10m 
        memory: 40Mi

  disablePolicyChecks: false
...
grafana:
  enabled: true

tracing:
  enabled: true

kiali:
  enabled: true
  createDemoSecret: true

gateways:
  istio-ingressgateway:
    type: NodePort
...

部署

helm template install/kubernetes/helm/istio --name istio --namespace istio-system \
--values install/kubernetes/helm/istio/values-istio-demo.yaml | kubectl apply -f -

[root@k8s01 istio-1.3.2]# kb edit deploy kiali -n istio-system

[root@k8s01 istio-1.3.2]# kb edit deploy kiali -n istio-system
...
image: kiali/kiali:v1.4
...
确认部署完成

svc

[root@k8s01 istio-1.3.2]# kb get svc -n istio-system
NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                                                                                                                                      AGE
istio-citadel            ClusterIP   10.254.161.158   <none>        8060/TCP,15014/TCP                                                                                         ...

pod

[root@k8s01 istio-1.3.2]# kb get pod -n istio-system
NAME                                      READY     STATUS      RESTARTS   AGE
istio-citadel-5586875b78-b2fcj            1/1       Running     0          5m
istio-galley-64588bcf66-xt8gz             1/1       Running     0          5m
...
卸载
$ helm template install/kubernetes/helm/istio --name istio --namespace istio-system | kubectl delete -f -
$ kubectl delete namespace istio-system

参考文章:

https://istio.io/v1.3/docs/setup/install/helm/

安装示例 bookinfo application

部署 app

1、给 namespace 添加 label istio-injection=enabled,使用自动注入 sidecar。

后面创建的 pod,都会在增加一个 sidecar 容器

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

2、部署应用

[root@k8s01 istio-1.3.2]# kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
service/details created
serviceaccount/bookinfo-details created
...

3、确认 pod 和 service 都部署成功

[root@k8s01 istio-1.3.2]# kb get po
NAME                               READY     STATUS    RESTARTS   AGE
details-v1-75f7c8897b-76mnx        1/1       Running   0          13m
...
[root@k8s01 istio-1.3.2]# kb get svc
NAME              TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
details           ClusterIP      10.254.11.235    <none>        9080/TCP       14m
...

5、确认 app 已经起来

[root@k8s01 istio-1.3.2]# kubectl exec -it $(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}') -c ratings -- curl productpage:9080/productpage | grep -o "<title>.*</title>"
<title>Simple Bookstore App</title>
检查 app 的 ingress ip 和 port

1、为 app 部署 ingress gateway

[root@k8s01 istio-1.3.2]# kb apply -f samples/bookinfo/networking/bookinfo-gateway.yaml 
gateway.networking.istio.io/bookinfo-gateway created
virtualservice.networking.istio.io/bookinfo created

2、确认 gateway 已经创建完成它

[root@k8s01 istio-1.3.2]# kb get gateway
NAME               AGE
bookinfo-gateway   40s

3、确认 ingress_host 和 ingress_port

查看 http ingress_port

[root@k8s01 istio-1.3.2]# kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}'
31380

查看 https ingress_port

[root@k8s01 istio-1.3.2]# kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].nodePort}'
31390

查看 ingress_host

[root@k8s01 istio-1.3.2]# kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items[0].status.hostIP}'
10.2.7.208

gateway_url ==> ingress_host:ingress_port

4、外部访问 app

[root@k8s01 istio-1.3.2]# curl -s http://10.2.7.208:31380/productpage | grep -o "<title>.*</title>"
<title>Simple Bookstore App</title>
部署默认目标规则

没有 enable mtls

[root@k8s01 istio-1.3.2]# kb apply -f  samples/bookinfo/networking/destination-rule-all.yaml

enable mtls

kb apply -f  samples/bookinfo/networking/destination-rule-all-mtls.yaml

查看目标规则

kb get destinationrule -o yaml
清理 app
samples/bookinfo/platform/kube/cleanup.sh

确认清理完成

kb get virtualservices
kb get destinationrules
kb get gateway
kb get pods
配置 request routing
  • 根据版本路由

把所有路由切换到 v1 版本

部署 virtualservice

[root@k8s01 istio-1.3.2]# kb apply -f samples/bookinfo/networking/virtual-service-all-v1.yaml

查看 virtualservice

kb get virtualservices -o yaml 

查看 destinationrule

kb get destinationrule -o yaml

浏览器多次刷新 http://10.2.7.200:31380/productpage#

删除 virtualservice

kb delete -f samples/bookinfo/networking/virtual-service-all-v1.yaml
  • 根据用户路由

控制用户 jason 到 v2,其他的到 v1

[root@k8s01 istio-1.3.2]# kb apply -f samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml
virtualservice.networking.istio.io/reviews created

浏览器多次刷新 http://10.2.7.200:31380/productpage#, jason 登录后再次刷新

  • 链路切换

全切 v1

kb apply -f samples/bookinfo/networking/virtual-service-all-v1.yaml

v1、v3 各 50% 流量

kb apply -f samples/bookinfo/networking/virtual-service-reviews-50-v3.yaml

全切 v3

kb apply -f samples/bookinfo/networking/virtual-service-reviews-v3.yaml 
  • 故障注入
kb apply -f samples/bookinfo/networking/virtual-service-all-v1.yaml
kb apply -f samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml

注入错误,让 jason 用户有 7s 的延时

vim samples/bookinfo/networking/virtual-service-ratings-test-delay.yaml

访问页面发现出错,因为我们希望 7s 内返回,这样就发现了一个延迟的 bug

参考文章:

https://istio.io/v1.3/docs/tasks/traffic-management/ingress/ingress-control/#determining-the-ingress-ip-and-ports

https://istio.io/v1.3/docs/examples/bookinfo/

https://istio.io/v1.3/docs/tasks/traffic-management/request-routing/

https://istio.io/v1.3/docs/concepts/traffic-management/

可视化 mesh

defautl 部署,还需要部署 jaeger、zipkin 等

demo 部署不需要

1、定义 kiali 用户、密码。如果前面使用的是 kistio-demo.yaml 部署 istio,那么 1,2,3,都不需要执行,默认kiali 用户 admin,密码 admin123

[root@k8s01 istio-1.3.2]# echo -n admin | base64 
YWRtaW4=
[root@k8s01 istio-1.3.2]# echo -n admin123 | base64
YWRtaW4xMjM=

2、创建 secret,注意 secret 中需要使用 echo -n 消除 \n,否则登陆密码会出错

[root@k8s01 istio-1.3.2]# cat kiali-secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: kiali
  namespace: istio-system
  labels:
    app: kiali
type: Opaque
data:
  username: YWRtaW4=
  passphrase: YWRtaW4xMjM=
[root@k8s01 istio-1.3.2]# kb apply -f kiali-secret.yaml
secret/kiali created

或者

kubectl create secret generic kiali -n istio-system --from-literal=username=admin --from-literal=passphrase=admin

3、通过 helm 部署 kiali。

helm template --set kiali.enabled=true install/kubernetes/helm/istio --name istio --namespace istio-system > istio.yaml

如果安装了 jaeger 和 grafana,需要与 kiali 集成

$ helm template \
    --set kiali.enabled=true \
    --set "kiali.dashboard.jaegerURL=http://jaeger-query:16686";; \
    --set "kiali.dashboard.grafanaURL=http://grafana:3000";; \
    install/kubernetes/helm/istio \
    --name istio --namespace istio-system > istio.yaml

修改 istio.yaml kiali image

...
       - image: "kiali/kiali:v1.4"
...

修改 istio.yaml istio-ingressgateway Service NodePort

...
apiVersion: v1
kind: Service
metadata:
  name: istio-ingressgateway
  namespace: istio-system
  annotations:
  labels:
    chart: gateways
    heritage: Tiller
    release: istio
    app: istio-ingressgateway
    istio: ingressgateway
spec:
  type: NodePort
...

部署

kb apply -f istio.yaml

以 nodeport 的形式暴露 kiali 服务

[root@k8s01 istio-1.3.2]# kb expose service kiali --port=20001 --target-port=20001 --name=kiali-external --type=NodePort -n istio-system
service/kiali-external exposed

清除

kubectl delete all,secrets,sa,configmaps,deployments,ingresses,clusterroles,clusterrolebindings,virtualservices,destinationrules,customresourcedefinitions --selector=app=kiali -n istio-system
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值