Istio入门操练

Istio入门操练

安装Istio

前提安装好Rancher及k8s集群

  1. 在应用商店选择istio,勾选Enabled the Grafana Component,启动

  2. 检查Rancher面板istio所有工作负载均处于良好状态
  3. 在默认命名空间里添加一个istio-injected标签(该标签将使得Istio-Sidecar-Injector自动将Envoy容器注入您的应用程序节点),Istio sidecar容器会自动注入你的节点,运行下方的kubectl命令
    1
    2
    3
    4
    5
    6
    7
    8
    9
     > kubectl label namespace default istio-injection=enabled
     namespace "default" labeled
     > kubectl get namespace -L istio-injection
     NAME            STATUS    AGE       ISTIO-INJECTION
     cattle-system   Active    1h
     default         Active    1h        enabled
     istio-system    Active    37m
     kube-public     Active    1h
     kube-system     Active    1h
    

安装BookInfo应用

  1. 在default namespace部署Bookinfo示例应用

    • 点击Import Yaml;下载bookinfo.yaml(https://info.rancher.com/hubfs/bookinfo.yaml)到本地;

    • 当你进入Import Yaml菜单之后,通过从文件读取,将其上传至Rancher;
    • 对于 Import Mode,选择【集群:将任何资源直接导入此集群】Cluster: Direct import of any resources into this cluster;

    • 点击【导入/Import】。
    • 或者使用kubectl部署
      1
          kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.1/samples/bookinfo/platform/kube/bookinfo.yaml
      
  2. 确认所有服务和Pod都没问题

    1
    2
     kubectl get services
     kubectl get pods
    
  3. 发送curl命令确认BookInfo正在运行

    1
    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>
    
  4. 确定Ingress的Ip和端口
    • 为应用程序配置启动网关
      1
      2
      3
      4
        $ kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.1/samples/bookinfo/networking/bookinfo-gateway.yaml
        $ kubectl get gateway
        NAME               AGE
        bookinfo-gateway   32s
      
    • 设置访问网关的 INGRESS_HOST 和 INGRESS_PORT 变量。确认并设置 确定如果IP和端口
    • 设置 GATEWAY_URL
      1
         export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
      
  5. 确认gateway正常工作 用浏览器打开网址 http://$GATEWAY_URL/productpage,来浏览应用的 Web 页面。如果刷新几次应用的页面,就会看到 productpage 页面中会随机展示 reviews 服务的不同版本的效果(红色、黑色的星形或者没有显示)。reviews 服务出现这种情况是因为我们还没有使用 Istio 来控制版本的路由。

部署问题

  1. 镜像无法拉取

    在安装过程中遇到quay.io的镜像无法拉取,需要用代理或其他方式拉取,拉取后用tag修改名称即可,例如使用中国科大镜像站(http://mirrors.ustc.edu.cn/)

    1
    2
     docker pull quay.mirrors.ustc.edu.cn/jetstack/cert-manager-controller:v0.3.1
     docker tag quay.mirrors.ustc.edu.cn/jetstack/cert-manager-controller:v0.3.1 quay.io/jetstack/cert-manager-controller:v0.3.1
    
  2. quay资源可以在host中加入89.31.125.19 quay.io就可以完成加速

参考网站

如何使用Rancher 2.0在Kubernetes集群上部署Istio

Istio中文文档

Istio系列博客