istio的安装,流控初步了解

istio 安装

前提:

kubernetes 1.7.3及以上,并开启RBAC
kubernetes 1.9 以上,支持自动安装sidecar injection

环境要求:

1、开启serviceaccount
2、网络组件
3、有dns

下载源码包:

cd /usr/local/src/
wget https://github.com/istio/istio/releases/download/0.7.1/istio-0.7.1-linux.tar.gz
tar -zxf istio-0.7.1-linux.tar.gz

安装

cd istio-0.7.1
cp bin/istioctl /usr/local/sbin/
kubectl apply -f install/kubernetes/istio.yaml

如果要启动tls

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

所有项目在namespace istio-system查看

image名称,可以提前下载

docker.io/istio/proxy:0.7.1
docker.io/istio/mixer:0.7.1
docker.io/istio/pilot:0.7.1
docker.io/istio/istio-ca:0.7.1

查看是否安装成功

kubectl get svc -n istio-system
NAME            TYPE            CLUSTER-IP      EXTERNAL-IP   PORT(S)                                                             AGE
istio-ingress   LoadBalancer   10.111.150.31    <pending>     80:31691/TCP,443:30512/TCP                                          4h
istio-mixer     ClusterIP      10.100.150.25    <none>        9091/TCP,15004/TCP,9093/TCP,9094/TCP,9102/TCP,9125/UDP,42422/TCP    4h
istio-pilot     ClusterIP      10.108.203.112   <none>        15003/TCP,15005/TCP,15007/TCP,15010/TCP,8080/TCP,9093/TCP,443/TCP   4h

注: 如果集群不支持load banlance,EXTERNAL-IP 就是pending状态。可以设置NodePort或者端口转发实现访问

查看pod是否正常

kubectl get pods -n istio-system
NAME                             READY     STATUS    RESTARTS   AGE
istio-ca-5d495f8897-dvpg6        1/1       Running   0          4h
istio-ingress-5b5db76895-wqndc   1/1       Running   0          4h
istio-mixer-db9f8d47d-7gn9h      3/3       Running   0          4h
istio-pilot-84fcc8d4d7-lk9n2     2/2       Running   0          4h

如果是1.9版本,还有pod :istio-sidecar-injector-

部署应用

注:应用必须是 HTTP/1.1 or HTTP/2.0, 因为HTTP/1.0 是不支持的

如果是1.9版本,开启了pod(istio-sidecar-injector),可以直接使用kubectl create命令

kubectl label namespace <namespace> istio-injection=enabled
kubectl create -n <namespace> -f <your-app>.yaml

如果没安装Istio-sidecar-injector,必须手动添加
kubectl create -f &lt;(istioctl kube-inject -f &lt;your-app&gt;.yaml)

卸载

1、安装的时候 启用 sidecar injector

kubectl delete -f install/kubernetes/istio-sidecar-injector-with-ca-bundle.yaml

2、没有tls认证:

kubectl delete -f install/kubernetes/istio.yaml

3、有tls认证:

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

使用举例

这里以helloworld举例 目录位置istio-0.7.1/samples/helloworld

因为集群版本是1.8,没有内置injector,需要手动更改yaml

istioctl kube-inject -f helloworld.yaml -o helloworld-istio.yaml

扫描二维码关注公众号,回复: 79579 查看本文章

使用新的yaml文件,部署服务
kubectl create -f helloworld-istio.yaml

获取ingress url 和端口

export HELLOWORLD_URL=$(kubectl get po -l istio=ingress -o 'jsonpath={.items[0].status.hostIP}'):$(kubectl get svc istio-ingress -o 'jsonpath={.spec.ports[0].nodePort}')

查看服务是否正常
curl http://$HELLOWORLD_URL/hello

注: 因为集群没有loadbalance,只能用nodeport访问

获取node ip
kubectl get po -l istio=ingress -n istio-system -o 'jsonpath={.items[0].status.hostIP}'

获取node port
kubectl get svc istio-ingress -n istio-system -o 'jsonpath={.spec.ports[0].nodePort}'

现在访问
curl http://$HELLOWORLD_URL/hello

发现规则是轮询到每个节点

route-rule编写

1、只能访问v1, route-rule-all-v1.yaml

apiVersion: config.istio.io/v1alpha2
kind: RouteRule
metadata:
  name: helloword-default
spec:
  destination:
    name: helloworld
  route:
  - labels:
      version: v1

2、只能访问v2, route-rule-all-v2.yaml

apiVersion: config.istio.io/v1alpha2
kind: RouteRule
metadata:
  name: helloword-default
spec:
  destination:
    name: helloworld
  route:
  - labels:
      version: v2

istio命令

删除规则
istioctl delete routerules helloword-default

查看规则
istioctl get routerules

猜你喜欢

转载自blog.51cto.com/foxhound/2108516