摘要:本文主要向大家介绍了【云计算】istiov1.0安装使用教程实例,通过具体的内容向大家展现,希望对大家学习云计算有所帮助。
本文主要向大家介绍了【云计算】istiov1.0安装使用教程实例,通过具体的内容向大家展现,希望对大家学习云计算有所帮助。
安装k8s 强势插播广告
三步安装,不多说
安装helm, 推荐生产环境用helm安装,可以调参
release地址
如我使用的2.9.1版本
yum install -y socat # 这个不装会报错
[root@istiohost ~]# wget https://storage.googleapis.com/kubernetes-helm/helm-v2.9.1-linux-amd64.tar.gz [root@istiohost ~]# tar zxvf helm-v2.9.1-linux-amd64.tar.gz [root@istiohost ~]# cp linux-amd64/helm /usr/bin
先创建一个service account 把管理员权限给helm:
[root@istiohost ~]# cat helmserviceaccount.yaml apiVersion: v1 kind: ServiceAccount metadata: name: tiller namespace: kube-system --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: tiller-clusterrolebinding subjects: - kind: ServiceAccount name: tiller namespace: kube-system roleRef: kind: ClusterRole name: cluster-admin apiGroup: ""
kubectl create -f helmserviceaccount.yaml
安装helm 服务端 tiller :
helm init --service-account tiller # 如果已安装更新加 --upgrade 参数 helm list #没任何返回表示成功
安装istio
curl -L https://git.io/getLatestIstio | sh - cd istio-1.0.0/ export PATH=$PWD/bin:$PATH
helm 2.10.0以前的版本需要装一下CRD:
kubectl apply -f install/kubernetes/helm/istio/templates/crds.yaml kubectl apply -f install/kubernetes/helm/istio/charts/certmanager/templates/crds.yaml
安装istio, 由于你没有LB所以用NodePort代替:
helm install install/kubernetes/helm/istio --name istio --namespace istio-system --set gateways.istio-ingressgateway.type=NodePort --set gateways.istio-egressgateway.type=NodePort
安装成功:
[root@istiohost istio-1.0.0]# kubectl get pod -n istio-system NAME READY STATUS RESTARTS AGE istio-citadel-7d8f9748c5-ntqnp 1/1 Running 0 5m istio-egressgateway-676c8546c5-2w4cq 1/1 Running 0 5m istio-galley-5669f7c9b-mkxjg 1/1 Running 0 5m istio-ingressgateway-5475685bbb-96mbr 1/1 Running 0 5m istio-pilot-5795d6d695-gr4h4 2/2 Running 0 5m istio-policy-7f945bf487-gkpxr 2/2 Running 0 5m istio-sidecar-injector-d96cd9459-674pk 1/1 Running 0 5m istio-statsd-prom-bridge-549d687fd9-6cbzs 1/1 Running 0 5m istio-telemetry-6c587bdbc4-jndjn 2/2 Running 0 5m prometheus-6ffc56584f-98mr9 1/1 Running 0 5m [root@istiohost istio-1.0.0]# kubectl get s -n istio-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE istio-citadel ClusterIP 10.108.253.89
productpage 调用details和reviews渲染页面 details包含书本信息 reviews 书本反馈,调用ratings服务 ratings 书本租借信息
reviews服务有三个版本:
V1 不请求ratings V2 请求ratings,返回1到5个黑星 V3 请求ratings,返回1到5个红星
数据平面:
安装应用:
kubectl apply -f <(istioctl kube-inject -f samples/bookinfo/platform/kube/bookinfo.yaml)
安装完成:
[root@istiohost istio-1.0.0]# kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE details ClusterIP 10.104.66.31
创建一个gateway,这是为了集群外可以访问
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
浏览器访问url:
47.254.28.88是我的节点ip,使用nodeport模式
//47.254.28.88:31380/productpage
连续点击三次,你会发现右边没星星-> 黑星星-> 红星星切换,对应三个版本的review,默认策略是轮询
创建destination rules, 配置路由访问规则,现在还是轮询
kubectl apply -f samples/bookinfo/networking/destination-rule-all.yaml
把所有路由切换到v1版本
kubectl apply -f samples/bookinfo/networking/virtual-service-all-v1.yaml
这样执行完后,不管怎么刷页面,我们都看不到星星,因为v1版本没星
可以看到destination是这样的:
http: - route: - destination: host: details subset: v1
试想如此我们做版本切换将是何等简单
kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml
你会发现用jason用户登录就能看到黑星星,而其它方式看到的页面都是无星星
因为这个user走了v2版本,能不强大? 那当然还能根据header什么的做路由了,就不多说了
http: - match: - headers: end-user: exact: jason route: - destination: host: reviews subset: v2 - route: - destination: host: reviews subset: v1
kubectl apply -f samples/bookinfo/networking/virtual-service-all-v1.yaml kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml
假设代码里有个bug,用户jason, reviews:v2 访问ratings时会卡10s, 我们任然希望端到端的测试能正常走完
kubectl apply -f samples/bookinfo/networking/virtual-service-ratings-test-delay.yaml
注入错误让jason用户有个7s的延迟
hosts: - ratings http: - fault: delay: fixedDelay: 7s percent: 100 match: - headers: end-user: exact: jason route: - destination: host: ratings subset: v1 - route: - destination: host: ratings subset: v1
这时访问页面显然会出错,因为我们希望7s内能返回,这样我们就发现了一个延迟的bug
Error fetching product reviews! Sorry, product reviews are currently unavailable for this book.
所以我们就可能通过故障注入去发现这些异常现象
我们先把50%流量发送给reviews:v1 50%流量发送给v3,然后再把100%的流量都切给v3
kubectl apply -f samples/bookinfo/networking/virtual-service-all-v1.yaml
此时不论刷几遍,都没有星星
kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-50-v3.yaml
- route: - destination: host: reviews subset: v1 weight: 50 - destination: host: reviews subset: v3 weight: 50
此时一会有星,一会没星,但是已经不是轮询算法了
kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-v3.yaml
这时不管怎么刷都是红心了
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标大数据云计算大数据安全频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号