istio使用教程

kubernetes各版本离线安装包

安装

安装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 svc -n istio-system
NAME                       TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                                                                                                     AGE
istio-citadel              ClusterIP   10.108.253.89    <none>        8060/TCP,9093/TCP                                                                                           5m
istio-egressgateway        NodePort    10.96.151.14     <none>        80:30830/TCP,443:30038/TCP                                                                                  5m
istio-galley               ClusterIP   10.102.83.130    <none>        443/TCP,9093/TCP                                                                                            5m
istio-ingressgateway       NodePort    10.99.194.13     <none>        80:31380/TCP,443:31390/TCP,31400:31400/TCP,15011:31577/TCP,8060:30037/TCP,15030:31855/TCP,15031:30775/TCP   5m
istio-pilot                ClusterIP   10.101.4.143     <none>        15010/TCP,15011/TCP,8080/TCP,9093/TCP                                                                       5m
istio-policy               ClusterIP   10.106.221.68    <none>        9091/TCP,15004/TCP,9093/TCP                                                                                 5m
istio-sidecar-injector     ClusterIP   10.100.5.170     <none>        443/TCP                                                                                                     5m
istio-statsd-prom-bridge   ClusterIP   10.107.28.242    <none>        9102/TCP,9125/UDP                                                                                           5m
istio-telemetry            ClusterIP   10.105.66.20     <none>        9091/TCP,15004/TCP,9093/TCP,42422/TCP                                                                       5m
prometheus                 ClusterIP   10.103.128.152   <none>        9090/TCP

使用教程

官网事例 Bookinfo Application

  • 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    <none>        9080/TCP   2m
kubernetes    ClusterIP   10.96.0.1       <none>        443/TCP    4h
productpage   ClusterIP   10.109.68.13    <none>        9080/TCP   2m
ratings       ClusterIP   10.99.55.110    <none>        9080/TCP   2m
reviews       ClusterIP   10.102.19.129   <none>        9080/TCP   2m
[root@istiohost istio-1.0.0]# kubectl get pods
NAME                              READY     STATUS    RESTARTS   AGE
details-v1-fc9649d9c-dpnlp        2/2       Running   0          2m
productpage-v1-58845c779c-7g8th   2/2       Running   0          2m
ratings-v1-6cc485c997-fb7nh       2/2       Running   0          2m
reviews-v1-76987687b7-x5n7z       2/2       Running   0          2m
reviews-v2-86749dcd5-xchzb        2/2       Running   0          2m
reviews-v3-7f4746b959-nthrq       2/2       Running   0          2m

创建一个gateway,这是为了集群外可以访问

kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml

浏览器访问url:47.254.28.88是我的节点ip,使用nodeport模式

http://47.254.28.88:31380/productpage 

连续点击三次,你会发现右边没星星-> 黑星星-> 红星星切换,对应三个版本的review,默认策略是轮询

创建destination rules, 配置路由访问规则,现在还是轮询

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

智能路由

请求路由 request routing

根据版本路由

把所有路由切换到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

故障注入 Fault injection

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.

所以我们就可能通过故障注入去发现这些异常现象

链路切换 Traffic Shifting

我们先把50%流量发送给reviews:v1 50%流量发送给v3,然后再把100%的流量都切给v3

把100%流量切到v1

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

此时不论刷几遍,都没有星星

v1 v3各50%流量

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

此时一会有星,一会没星,但是已经不是轮询算法了

全切v3

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

这时不管怎么刷都是红心了

扫码关注sealyun探讨可加QQ群:98488045

<think>我们正在处理用户关于Istio服务网格的学习请求。根据提供的引用资料,用户需要入门教程使用指南。 引用[1]提到Istio是Google开源的Service Mesh框架,使用Go语言开发,是Service Mesh领域的集大成者。 引用[2]提供了Istio问题排查的命令,包括使用Kubernetes命令查看配置细节、代理日志和目的地规则。 引用[3]展示了手动将pod注册到服务的命令示例。 引用[4]是关于允许Pod在Master节点上调度的命令。 用户需求:学习Istio服务网格的使用和配置,要求入门教程使用指南。 由于用户是入门,我们需要从基础概念开始,逐步介绍安装、配置和使用。同时,根据引用资料,我们可以整合一些关键命令和实践。 回答结构: 1. Istio简介 2. 安装Istio 3. 核心功能与配置(流量管理、安全、可观测性) 4. 常用命令(参考引用资料) 5. 调试与问题排查(参考引用资料[2]) 6. 实践示例 注意:引用资料中提到的命令和操作需要整合到相应部分。 根据引用[1]和[2],我们还可以强调Istio的复杂性和调试方法,但入门指南应侧重基础。 由于用户要求入门,我们不需要深入进阶内容,但可以提及进阶学习资源(如引用[1]的进阶实战)。 同时,生成相关问题。</think>### Istio 服务网格入门指南 #### 1. **Istio核心概念** Istio 是由 Google 开源的 Service Mesh 框架,使用 Go 语言开发,提供以下核心功能: - **流量管理**:动态路由、金丝雀发布、故障注入 - **安全**:服务间 mTLS 加密、RBAC 策略 - **可观测性**:指标监控(Prometheus)、分布式追踪(Jaeger) - **策略执行**:速率限制、配额管理[^1] #### 2. **安装部署** **步骤:** 1. 下载最新版 Istio: ```bash curl -L https://istio.io/downloadIstio | sh - ``` 2. 安装到 Kubernetes 集群: ```bash istioctl install --set profile=demo -y ``` 3. 验证安装: ```bash kubectl get pods -n istio-system ``` #### 3. **基础配置示例** **流量路由(VirtualService):** ```yaml apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: bookinfo spec: hosts: - bookinfo.com http: - route: - destination: host: reviews subset: v1 - destination: host: reviews subset: v2 ``` **服务注册(手动添加 Pod):** ```bash istioctl register reviews-svc 10.1.1.100 9080 # 注册服务名 Pod IP 端口 [^3] ``` #### 4. **调试与监控** - **查看代理日志**: ```bash kubectl logs <pod-name> -c istio-proxy ``` - **检查目标规则**: ```bash istioctl get destinationrule ``` - **Master 节点调度**: ```bash kubectl taint nodes <node-name> node-role.kubernetes.io/master- [^4] ``` #### 5. **学习资源推荐** - 入门实践:[Istio 官方文档](https://istio.io/latest/docs/) - 进阶实战:《Istio 服务网格进阶实战.pdf》[^1] - 问题排查指南:[Istio 服务网格入门指南(四)](引用[2]) --- ### 相关问题 1. 如何配置 Istio 实现金丝雀发布? 2. Istio 中 mTLS 加密的配置步骤是什么? 3. 如何通过 Prometheus 监控 Istio 服务网格的性能指标? 4. 在 Istio 中如何实现服务间的速率限制? 5. Istio 与 Kubernetes Ingress 的主要区别是什么?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值