service mesh istio-1.0 快速安装体验

栏目: 编程工具 · 发布时间: 5年前

istio 是一个 service mesh 开源实现,由Google/IBM/Lyft共同开发。架构图如下:

service mesh istio-1.0 快速安装体验

安装

安装k8s集群

参考文章

安装 istioctl

# 去下面的地址下载压缩包
# https://github.com/istio/istio/releases
wget https://github.com/istio/istio/releases/download/1.0.0/istio-1.0.0-linux.tar.gz
tar xf istio-1.0.0-linux.tar.gz

# 安装配置环境变量
mv istio-1.0.0 /usr/local/
ln -sv /usr/local/istio-1.0.0 /usr/local/istio
echo 'export PATH=/usr/local/istio/bin:$PATH' > /etc/profile.d/istio.sh
source /etc/profile.d/istio.sh
istioctl version
复制代码

在k8s集群中安装istio

# 如果环境不是云环境,不支持LoadBalancer
# 作如下修改,使得 ingressgateway 监听在80和443端口
# 修改使用主机端口映射
# 使用此修改版本之后,每台机器只能运行单个实例
# 大概在3027行左右
cd /usr/local/istio
sudo cp install/kubernetes/istio-demo.yaml install/kubernetes/istio-demo.yaml.ori
sudo vim install/kubernetes/istio-demo.yaml
...
apiVersion: extensions/v1beta1
# kind: Deployment
# 使用DaemonSet部署方式
kind: DaemonSet
metadata:
  name: istio-ingressgateway
  namespace: istio-system
  labels:
    app: ingressgateway
    chart: gateways-1.0.0
    release: RELEASE-NAME
    heritage: Tiller
    app: istio-ingressgateway
    istio: ingressgateway
spec:
  # DaemonSet不支持replicas
  # replicas: 1
  template:
    metadata:
      labels:
        app: istio-ingressgateway
        istio: ingressgateway
      annotations:
        sidecar.istio.io/inject: "false"
        scheduler.alpha.kubernetes.io/critical-pod: ""
    spec:
      serviceAccountName: istio-ingressgateway-service-account
      containers:
        - name: ingressgateway
          image: "gcr.io/istio-release/proxyv2:1.0.0"
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
              # 主机80端口映射
              hostPort: 80
            - containerPort: 443
              # 主机443端口映射
              hostPort: 443
...

# 替换镜像地址
sudo sed -i 's@gcr.io/istio-release@docker.io/istio@g' install/kubernetes/istio-demo.yaml
sudo sed -i 's@quay.io/coreos/hyperkube:v1.7.6_coreos.0@registry.cn-shanghai.aliyuncs.com/gcr-k8s/hyperkube:v1.7.6_coreos.0@g' install/kubernetes/istio-demo.yaml

# 查看镜像地址
grep 'image:' install/kubernetes/istio-demo.yaml

# 安装 CRDs
# 等待数秒
kubectl apply -f install/kubernetes/helm/istio/templates/crds.yaml -n istio-system
kubectl get crd

# 安装不使用认证(不使用tls)
# 如果机器内存过小会无法成功启动
# 实验使用3台虚拟机每台3G内存
kubectl apply -f install/kubernetes/istio-demo.yaml

# 查看状态
kubectl get svc -n istio-system
kubectl get pods -n istio-system
复制代码

注意

istio-1.0.0 默认已经开启了自动注入功能以及其他日志监控和追踪的相关组件如

  • istio-tracing
  • istio-telemetry
  • grafana
  • prometheus
  • servicegraph

启用自动注入 sidecar

  • 不开启自动注入部署应用需要使用如下方式的命令 kubectl apply -f <(istioctl kube-inject -f samples/bookinfo/kube/bookinfo.yaml)

  • 开启自动注入后,使用正常命令即可部署应用 kubectl apply -f samples/bookinfo/kube/bookinfo.yaml

# istio-1.0.0 默认已经开启了自动注入功能

# k8s 1.9 及之后的版本才能使用自动注入功能
# 查看是否支持
kubectl api-versions | grep admissionregistration

# 除了要满足以上条件外还需要检查kube-apiserver启动的参数
# k8s 1.9 版本要确保 --admission-control 里有 MutatingAdmissionWebhook,ValidatingAdmissionWebhook
# k8s 1.9 之后的版本要确保 --enable-admission-plugins 里有MutatingAdmissionWebhook,ValidatingAdmissionWebhook

# 测试自动注入
# 创建
kubectl apply -f samples/sleep/sleep.yaml 
kubectl get deployment -o wide
kubectl get pod

# 设置 default namespace 开启自动注入
kubectl label namespace default istio-injection=enabled
kubectl get namespace -L istio-injection

# 删除创建的pod,等待重建
kubectl delete pod $(kubectl get pod | grep sleep | cut -d ' ' -f 1)

# 查看重建后的pod
# 查看是否有istio-proxy容器
kubectl get pod
kubectl describe pod $(kubectl get pod | grep sleep | cut -d ' ' -f 1)

# 清理
kubectl delete -f samples/sleep/sleep.yaml 

# 关闭自动注入
kubectl label namespace default istio-injection-

# 关闭部分pod的自动注入功能
...
  template:
    metadata:
      annotations:
        sidecar.istio.io/inject: "false"
...
复制代码

部署官方测试用例

# default开启自动注入
kubectl label namespace default istio-injection=enabled

# 部署 bookinfo
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml

# 创建 gateway
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml

# 查看状态
kubectl get services
kubectl get pods
istioctl get gateway
复制代码

访问测试

# 命令行访问测试
export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
NODE_NAME=$(kubectl get no | grep '<none>' | head -1 | awk '{print $1}')
NODE_IP=$(ping -c 1 $NODE_NAME | grep PING | awk '{print $3}' | tr -d '()')
export GATEWAY_URL=$NODE_IP:$INGRESS_PORT
echo $GATEWAY_URL

curl -o /dev/null -s -w "%{http_code}\n" http://${GATEWAY_URL}/productpage

# 浏览器访问测试
echo "http://${GATEWAY_URL}/productpage"

# 使用daemonset方式部署可以使用如下方式访问
# 11.11.11.112为其中一个node节点的ip
curl http://11.11.11.112/productpage

# 清理
samples/bookinfo/platform/kube/cleanup.sh
复制代码

清理

# 清理istio
kubectl delete -f install/kubernetes/helm/istio/templates/crds.yaml -n istio-system
kubectl delete -f install/kubernetes/istio-demo.yaml

# kubectl delete -f install/kubernetes/istio-demo-auth.yaml
复制代码

使用helm安装istio

安装helm

参考文章

安装istio

# 查看配置
cd /usr/local/istio
egrep -v "^$|#" install/kubernetes/helm/istio/values.yaml

# 安装 CRDs
kubectl apply -f install/kubernetes/helm/istio/templates/crds.yaml
kubectl get crd

# 根据上面查看的配置和需求配置相关参数
# 部署
helm install install/kubernetes/helm/istio --name istio --namespace istio-system \
--set ingress.enabled=false \
--set global.hub="docker.io/istio" \
--set global.hyperkube.hub="registry.cn-shanghai.aliyuncs.com/gcr-k8s" \
--set gateways.istio-ingressgateway.type=NodePort \
--set gateways.istio-egressgateway.type=NodePort

# 查看
helm ls
kubectl get pods -n istio-system
kubectl get svc -n istio-system

# 运行之前的测试

# 清理
helm delete --purge istio
kubectl delete -f install/kubernetes/helm/istio/templates/crds.yaml -n istio-system
复制代码

参考文档

  • https://istio.io/docs/setup/kubernetes/quick-start.html
  • https://istio.io/docs/guides/bookinfo.html
  • https://istio.io/docs/setup/kubernetes/sidecar-injection.html#automatic-sidecar-injection

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Sexy Web Design

Sexy Web Design

Elliot Stocks / SitePoint / 2009-03-28 / $39.95

Description A guide to building usable, aesthetically pleasing interfaces for web sites and web applications by applying timeless principles of user-centered design. This book focuses on practical ......一起来看看 《Sexy Web Design》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具