istio-安装(0.7.1)

环境:

1. kubernetes 1.9.8

2. istio 0.7.1

一、kubernetes kube-apiserver 增加权限配置(MutatingAdmissionWebhook,ValidatingAdmissionWebhook):

--admission-control=NamespaceLifecycle,LimitRanger,ServiceAccount,PersistentVolumeLabel,DefaultStorageClass,DefaultTolerationSeconds,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota

二、下载

1. 在istio-Releases下载相应的版本,或使用下面脚本下载最新版本:

curl -L https://git.io/getLatestIstio | sh -

2. 解压后,目录如下:

mac-temp:istio-0.7.1 $ ls -l
total 48
-rw-r--r--   1 zyh  staff  11343  3 31 03:17 LICENSE
-rw-r--r--   1 zyh  staff   5881  3 31 03:17 README.md
drwxr-xr-x   3 zyh  staff     96  3 31 03:17 bin #istioctl 用来手动注入 Envoy sidecar 、创建路由和策略...
drwxr-xr-x   9 zyh  staff    288  3 31 03:17 install  #kubernetes 的 yaml 安装文件
-rw-r--r--   1 zyh  staff    638  3 31 03:17 istio.VERSION
drwxr-xr-x  10 zyh  staff    320  3 31 03:17 samples  #例子文件
drwxr-xr-x  18 zyh  staff    576  3 31 03:17 tools

3. 把istioctl加在PATH中

export PATH=$PWD/bin:$PATH

4. 修改ingress的类型loadbalancer->NodePort (可选)

由于kubernetes 使用二进制文件在本地安装,不支持loadbalancer,istio默认安装的ingress使用loadbalancer,所以需要修改install/kubernetes/istion.yaml中定义ingress部分,修改为NodePort

apiVersion: v1
kind: Service
metadata:
  name: istio-ingress
  namespace: istio-system
  labels:
    istio: ingress
spec:
  type: NodePort
  ports:
  - port: 80
    nodePort: 80
    name: http
  - port: 443
    nodePort: 443
    name: https
  selector:
    istio: ingress

5. 安装核心组件:

a) 安装 Istio ,不启用 sidecar 之间的 TLS 双向认证:

kubectl apply -f install/kubernetes/istio.yaml
b)  安装 Istio ,启用 sidecar 之间的 TLS 双向认证:

kubectl apply -f install/kubernetes/istio-auth.yaml
6. 检查是否安装成功:
a) 确认已经安装下面的k8s service : istio-pilot, istio-mixer, istio-ingress.
$ kubectl get svc -n istio-system
NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                    AGE
istio-ingress  NodePort    10.254.162.226   <none>   80:80/TCP,443:443/TCP                2d
istio-mixer    ClusterIP   10.254.95.148    <none>   9091/TCP,15004/TCP,9093/TCP,9094/TCP,9102/TCP,9125/UDP,42422/TCP    2d
istio-pilot    ClusterIP   10.254.100.129   <none>   15003/TCP,15005/TCP,15007/TCP,15010/TCP,8080/TCP,9093/TCP,443/TCP   2d
istio-sidecar-injector   ClusterIP   10.254.158.211   <none>        443/TCP                    1d
b)确认下面kubernetes pod 已经运行成功:istio-pilot-*, istio-mixer-*, istio-ingress-*, istio-ca-*, istio-sidecar-injector-*(可选,自动注入sidecar).
$ kubectl get po -n istio-system
NAME                                     READY     STATUS    RESTARTS   AGE
istio-ca-86f55cc46f-vlp2d                1/1       Running   3          2d
istio-ingress-5bb556fcbf-wsg5m           1/1       Running   9          22h
istio-mixer-86f5df6997-p9n2r             3/3       Running   9          2d
istio-pilot-67d6ddbdf6-5ghcr             2/2       Running   7          2d
istio-sidecar-injector-5b8c78fd6-mvkdp   1/1       Running   2          1d
7.部署你的应用:
你的应用必须是HTTP/1.1 或 HTTP/2.0 协议,不支持HTTP/1.0
a)手动注入Envoy containers :

kubectl create -f <(istioctl kube-inject -f <your-app-spec>.yaml)
查看部署的应用:
$ kubectl get deployment nginx -o wide
NAME   DESIRED CURRENT UP-TO-DATE   AVAILABLE   AGE  CONTAINERS        IMAGES        SELECTOR
nginx  1       1       1            1           22h  nginx,istio-proxy nginx:1.7.9,docker.io/istio/proxy:0.7.1   app=nginx
可以看到,pod 被注入一个istio-proxy的容器。
 
b)自动注入Envoy containers ,后面再详细介绍.

       参考:

       http://istio.doczh.cn/docs/setup/kubernetes/sidecar-injection.html

       https://istio.io/docs/setup/kubernetes/sidecar-injection/       

       注入策略:
       如果配置了自动注入sidecar,但是有些pod,你如果不想注入sidecar,你可以使用以下方法:
      disabled - sidecar 注入器默认不会注入到 pod 中。添加pod模板定义中的annotations sidecar.istio.io/inject 值为 true会启用注入功能。
     enabled - sidecar 注入器默认会注入到 pod 中。添加pod模板定义中的annotations sidecar.istio.io/inject 值为 false会禁止注入功能。 ​

deployment如下:
apiVersion: extensions/v1beta1  
kind: Deployment  
metadata:  
  name: test-metrics  
spec:  
  replicas: 1  
  template:  
    metadata:  
      labels:  
        app: echo  
      annotations:  
        sidecar.istio.io/inject: "false"
...

8. 删除istio组件:

a) 不启用 sidecar 之间的 TLS 双向认证:

kubectl delete -f install/kubernetes/istio.yaml
b)  启用 sidecar 之间的 TLS 双向认证:

kubectl delete -f install/kubernetes/istio-auth.yaml

参考:

猜你喜欢

转载自blog.csdn.net/kozazyh/article/details/80515674