基于Kubernetes的Istio服务网格快速部署与测试
简介
Istio是一款流行的服务网格解决方案,帮助企业轻松构建服务网格架构。本文将基于Ubuntu 22.04系统,使用K8s 1.30版本,快速部署Istio 1.23,并通过Bookinfo案例演示其核心功能。
环境准备
操作系统:Ubuntu 22.04 Server
Kubernetes版本:1.30.0
Istio版本:1.23.3
部署与测试
安装Kubernetes集群
使用KubeKey工具快速部署K8s集群,具体步骤如下:
- 安装依赖:
sudo apt install socat conntrack ebtables ipset -y - 设置镜像源:
export KKZONE=cn - 下载并安装KubeKey:
wget https://github.com/kubesphere/kubekey/releases/download/v3.1.7/kubekey-v3.1.7-linux-amd64.tar.gz - 生成并配置集群文件:
./kk create config --with-kubernetes v1.30.0 - 启动集群:
./kk create cluster -f config-sample.yaml
安装Istio
使用Istioctl工具进行安装:
- 下载Istio二进制文件:
export ISTIO_VERSION=1.23.3 wget https://github.com/istio/istio/releases/download/1.23.3/istioctl-1.23.3-linux-amd64.tar.gz - 安装Istio:
istioctl install --set profile=demo - 验证安装:
kubectl -n istio-system get pods
测试Istio
部署Bookinfo示例应用:
- 创建必要的CRD:
curl -sL https://istio.io/downloadIstio | sh - - 启用Istio自动注入:
kubectl label namespace default istio-injection=enabled - 部署Bookinfo:
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml - 创建网关和虚拟服务:
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
访问测试
通过配置Nginx代理访问Bookinfo应用:
- 配置Nginx:
server { listen 80; server_name bookinfo.xg.com; location / { proxy_pass http://192.168.237.11:30425; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } - 添加域名解析:
echo "192.168.237.11 bookinfo.xg.com" >> /etc/hosts - 访问应用:
curl http://bookinfo.xg.com/productpage
注意事项
- 确保网络插件已正确配置
- 处理HTTP版本不兼容问题时,确保代理使用HTTP/1.1
- 可以根据实际网络环境调整负载均衡配置