kubernetes
  • Introduction
  • 安装
    • 组件端口
    • 二进制安装
    • Kubeadm
      • 安装单Master集群
      • 安装高可用集群(手动分发证书)
      • 安装高可用集群(自动上传证书)
      • 安装ETCD集群
      • 安装高可用集群(外部ETCD)
    • 启动参数解析
      • ETCD相关参数
  • 负载均衡
    • Service
    • Ingress
    • 安装MetalLB
    • Nginx-ingress-controller
      • 转发TCP与UDP服务
      • 启动参数
      • 自定义Nginx模板
  • 存储
    • Volume
    • PV与PVC
    • StorageClass
    • Local-PV
      • Static-Provisioner
    • 实践
      • Ceph-RBD
      • NFS
  • 有状态服务
    • Mysql实践
    • Operator
      • Etcd
      • Zookeeper
      • Mysql
  • 认证与授权
    • 认证
      • 实践
    • 授权
  • Helm
    • 安装
    • Chart
      • 依赖
    • Helm命令
    • Repository
  • 日志
  • 监控
    • Prometheus体系
      • Prometheus
        • 内置函数
        • 配置
          • 规则文件
        • PromQL
      • Exporter
        • Metrics
      • Grafana
        • 配置
      • AlertManager
        • 配置
    • 容器监控
      • Cadvisor的指标
      • k8s中部署Prom与Cadvisor
  • Istio
  • 资源预留
    • imagefs与nodefs
    • 总结
  • 集群联邦
    • 联邦DNS原理
    • 联邦DNS安装
    • 安装federation-v1
  • Other
    • ImagePullSecret
    • QOS
    • Apiserver的代理
    • 资源配额
Powered by GitBook
On this page
  • 安装istio
  • Bookinfo应用示例
  • 卸载
  • Reference

Was this helpful?

Istio

istio快速开始

  • 安装istion

    • 下载istio

    • 安装crd

    • 安装一个istio demo

    • 确认部署结果

  • Bookinfo应用示例

    • 为命名空间开启自动注入功能

    • 部署Bookinfo应用

    • 确认Bookinfo的Service与Pod都已正常

    • 验证从内部能访问应用

    • 从外部访问应用

      • 为应用定义入口网关

      • 使用NodePort从外部访问

    • 智能路由示例

      • 设置默认目标规则

      • 配置路由策略,只访问reviews-v1

      • 配置路由策略,特定用户的流量导向

  • 卸载

安装istio

1、下载istio

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

这里我们下载最新版本istio-1.1.7-linux.tar.gz,解压后结构如下:

istio-1.1.7
├── bin   (dir)
├── install  (dir)
├── istio.VERSION
├── LICENSE
├── README.md
├── samples  (dir)
└── tools  (dir)

2、安装crd

$ for i in install/kubernetes/helm/istio-init/files/crd*yaml; do kubectl apply -f $i; done

3、安装一个demo

$ kubectl apply -f install/kubernetes/istio-demo.yaml

4、确认部署结果

确认下列服务(除jaeger-agent外)已经部署并都具有各自的CLUSTER-IP

$ kubectl get service -n istio-system
NAME                     TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                                                                                                                                      AGE
grafana                  ClusterIP      10.105.55.147    <none>        3000/TCP                                                                                                                                     25s
istio-citadel            ClusterIP      10.100.67.233    <none>        8060/TCP,15014/TCP                                                                                                                           25s
istio-egressgateway      ClusterIP      10.109.167.188   <none>        80/TCP,443/TCP,15443/TCP                                                                                                                     26s
istio-galley             ClusterIP      10.108.40.187    <none>        443/TCP,15014/TCP,9901/TCP                                                                                                                   26s
istio-ingressgateway     LoadBalancer   10.97.152.170    <pending>     15020:32638/TCP,80:31380/TCP,443:31390/TCP,31400:31400/TCP,15029:31280/TCP,15030:30824/TCP,15031:32571/TCP,15032:32492/TCP,15443:30085/TCP   25s
istio-pilot              ClusterIP      10.110.241.218   <none>        15010/TCP,15011/TCP,8080/TCP,15014/TCP                                                                                                       25s
istio-policy             ClusterIP      10.110.26.166    <none>        9091/TCP,15004/TCP,15014/TCP                                                                                                                 25s
istio-sidecar-injector   ClusterIP      10.103.86.111    <none>        443/TCP                                                                                                                                      24s
istio-telemetry          ClusterIP      10.99.96.214     <none>        9091/TCP,15004/TCP,15014/TCP,42422/TCP                                                                                                       25s
jaeger-agent             ClusterIP      None             <none>        5775/UDP,6831/UDP,6832/UDP                                                                                                                   22s
jaeger-collector         ClusterIP      10.102.127.236   <none>        14267/TCP,14268/TCP                                                                                                                          22s
jaeger-query             ClusterIP      10.102.4.224     <none>        16686/TCP                                                                                                                                    22s
kiali                    ClusterIP      10.100.98.28     <none>        20001/TCP                                                                                                                                    25s
prometheus               ClusterIP      10.103.33.9      <none>        9090/TCP                                                                                                                                     25s
tracing                  ClusterIP      10.110.134.92    <none>        80/TCP                                                                                                                                       21s
zipkin                   ClusterIP      10.99.173.56     <none>        9411/TCP                                                                                                                                     22s

如果你的集群在一个没有外部负载均衡器支持的环境中运行,istio-ingressgateway 的 EXTERNAL-IP 会是<pending>。要访问这个网关,只能通过服务的 NodePort 或者使用端口转发来进行访问

确认必要的 Kubernetes Pod 都已经创建并且其STATUS的值是Running

$ kubectl get pod -n istio-system
kubectl get pod -n istio-system
NAME                                      READY   STATUS      RESTARTS   AGE
grafana-67c69bb567-tprnt                  1/1     Running     0          19h
istio-citadel-fc966574d-psht5             1/1     Running     1          19h
istio-cleanup-secrets-1.1.7-6fz75         0/1     Completed   0          19h
istio-egressgateway-6b4cd4d9f-nxjbs       1/1     Running     0          19h
istio-galley-cf776876f-xbzvx              1/1     Running     0          19h
istio-grafana-post-install-1.1.7-z5jd4    0/1     Completed   0          19h
istio-ingressgateway-59cc6ccbcb-bqdc5     1/1     Running     0          19h
istio-pilot-7b4dd9b748-lxblg              2/2     Running     0          19h
istio-policy-5bcc859488-2r52k             2/2     Running     44         19h
istio-security-post-install-1.1.7-ljpgz   0/1     Completed   0          19h
istio-sidecar-injector-c8ddbb99c-qq8q2    1/1     Running     1          19h
istio-telemetry-7678c9bb4d-l2m49          2/2     Running     44         19h
istio-tracing-5d8f57c8ff-rvkz5            1/1     Running     0          19h
kiali-d4d886dd7-wfh62                     1/1     Running     0          19h
prometheus-d8d46c5b5-8pjwl                1/1     Running     0          19h

Bookinfo应用示例

Bookinfo应用的架构图如下,它包含四个微服务:productpage、reviews、details及ratings,微服务之间的调用关系如图。

其中reviews服务有三个版本v1、v2和v3:

  • v1不会调用rating服务

  • v2会调用rating服务,并且会将评分以黑色的1到5颗星展示出来

  • v3会调用rating服务,并且会将评分以红色的1到5颗星展示出来

1、为命名空间开启自动注入功能

由于我们的Bookinfo是部署在default命名空间下,我们为default命名空间打上如下标签

$ kubectl label namespace default istio-injection=enabled

2、部署Bookinfo应用

bookinfo已经在istio的tar包中了

$ kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml

上面的命令会启动全部的四个服务,其中也包括了reviews服务的三个版本(三个Deployment、一个Service)

3、确认Bookinfo的Service与Pod都已正常

$  kubectl get service
NAME          TYPE           CLUSTER-IP       EXTERNAL-IP     PORT(S)          AGE
details       ClusterIP      10.98.169.211    <none>          9080/TCP         80s
kubernetes    ClusterIP      10.96.0.1        <none>          443/TCP          11d
productpage   ClusterIP      10.100.178.46    <none>          9080/TCP         79s
ratings       ClusterIP      10.111.212.42    <none>          9080/TCP         80s
reviews       ClusterIP      10.98.255.114    <none>          9080/TCP         80s

$ kubectl get pod
NAME                              READY   STATUS    RESTARTS   AGE
details-v1-65b966b497-nhln8       2/2     Running   0          7m34s
productpage-v1-79458795bc-kfw74   2/2     Running   0          7m33s
ratings-v1-5b7cd6c58f-p2fdc       2/2     Running   0          7m34s
reviews-v1-54c7c79486-dkmrq       2/2     Running   0          7m33s
reviews-v2-7dc5785684-vvbg8       2/2     Running   0          7m33s
reviews-v3-6c464d7bf4-2p27r       2/2     Running   0          7m33s

4、验证从内部能访问应用

从集群的某个台主机上使用ClusterIP访问productpage这个服务,ClusterIP在上面的kubectl get service中可以查到

$ curl 10.100.178.46:9080/productpage

5、从外部能访问应用

现在Bookinfo这个应用已经起来了,我们需要让它能够从集群外部访问,比如浏览器。为了达到这个目标,我们需要使用Istio Gateway

5.1 为应用定义入口网关

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

确认gateway与virtualservice已创建好

$ kubectl get gateway
NAME               AGE
bookinfo-gateway   90s

$ kubectl get virtualservice
NAME       GATEWAYS             HOSTS   AGE
bookinfo   [bookinfo-gateway]   [*]     98s

5.2 使用NodePort访问应用

通过如下的命令获取istio-ingressgateway服务的http2协议的NodePort

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

然后在浏览器中使用URLhttp://<IP>:<NodePort>/productpage来访问应用;其中IP是任意一个工作节点的IP。多刷新几次,我们会发现productpage会调用reviews服务的不同版本

如果productpage调用了reviews-v1,界面如下,没有星

如果productpage调用了reviews-v2,界面如下,有黑色的星

如果productpage调用了reviews-v3,界面如下,有红色的星

6、智能路由示例

6.1 设置目标规则

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

验证创建成功

$ kubectl get destinationrule
NAME          HOST          AGE
details       details       50s
productpage   productpage   50s
ratings       ratings       50s
reviews       reviews       50s

6.2 配置一个路由策略

接下来我们配置一个路由策略,让所有的访问都导向reviews的v1版本。执行如下命令创建virtual service

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

确认部署结果

$ kubectl get virtualservice
NAME          GATEWAYS             HOSTS           AGE
bookinfo      [bookinfo-gateway]   [*]             48m
details                            [details]       23s
productpage                        [productpage]   23s
ratings                            [ratings]       23s
reviews                            [reviews]       23s

然后从浏览器访问应用,多刷几次发现永远都是v1版本

6.3 配置另一个路由策略

我们在上面的基础上,再增加一种路由策略:基于用户的路由。在这种策略下,所有用户名为Jason的请求都会路由到服务reviews:v2上去。

注意,istio并没有内置的用户身份,该效果主要是通过在productpage的请求头的添加了一个end-user字段。

执行以下的创建基于用户的路由策略

$ kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml
virtualservice.networking.istio.io/reviews configured

然后在/productpage页面,用jason登录,多刷几次

卸载

1、删除Bookinfo示例的所有资源

在istio的根目录下执行

$ kubectl delete -R -f samples/bookinfo

2、去掉命名空间的label

$ kubectl label namespace default istio-injection-

3、卸载istio

$ kubectl delete -f install/kubernetes/istio-demo.yaml
$ for i in install/kubernetes/helm/istio-init/files/crd*yaml; do kubectl delete -f $i; done

Reference

  • https://istio.io/docs/setup/kubernetes/install/kubernetes/

  • https://istio.io/docs/examples/bookinfo/

    *https://istio.io/docs/tasks/traffic-management/ingress/#determining-the-ingress-ip-and-ports-when-using-a-node-port

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

Previousk8s中部署Prom与CadvisorNext资源预留

Last updated 5 years ago

Was this helpful?