k8s v1.35配置gateway, istio通过metalb vip访问

K8S V1.35新版已经不支持ingress了,所以要用istio代替。本文记录安装设置过程,供大家参考学习。

安装istio

  1. 下载
    https://github.com/istio/istio/releases 下载并解压
  2. 安装
    执行命令
sh 复制代码
./bin/istioctl install --set profile=default -y

Gateway api 安装

sh 复制代码
kubectl apply --server-side -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.4.1/standard-install.yaml

部署应用

yaml 复制代码
---
# 1.业务service
apiVersion: v1
kind: Service
metadata:
 name: tmp-gateway-service
 namespace: irmp-prod
spec:
 ports:
   - port: 8080
     targetPort: 8080
 selector:
   app: tmp-gateway
 type: ClusterIP

# 2. Gateway - 让 Istio 自动创建 Service
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
 name: tmp-gateway-gw
 namespace: irmp-prod
spec:
 gatewayClassName: istio
 listeners:
   - name: default
     hostname: "*.irmp.com"
     port: 80
     protocol: HTTP
     allowedRoutes:
       namespaces:
         from: All
---
# 3. HTTPRoute
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
 name: gw-httproute
 namespace: irmp-prod
spec:
 parentRefs:
   - name: tmp-gateway-gw
 hostnames:
   - "gw.irmp.com"
 rules:
   - matches:
       - path:
           type: PathPrefix
           value: /
     backendRefs:
       - name: tmp-gateway-service
         port: 8080

Gateway部署之后,它会自动安装一个tmp-gateway-gw-istio的Service,可以查看这个service的VIP,通过VIP可以访问你的服务了:

sh 复制代码
 export GW_IP=$(kubectl get svc tmp-gateway-gw-istio -n irmp-prod -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
 echo ${GW_IP}
 curl -H "Host: gw.irmp.com" http://${GW_IP}/
相关推荐
Benszen1 天前
K8S存储管理:Volume、PV/PVC与StorageClass详解
容器·rpc·kubernetes
在荒野的梦想1 天前
Docker + K8s 部署若依微服务 | 从 0 到 1 实战指南(Dockerfile + Harbor + Helm)
docker·微服务·kubernetes
fengyehongWorld1 天前
kubernetes Argo简介
云原生·容器·kubernetes
键盘鼓手苏苏1 天前
Kubernetes与GitOps最佳实践
云原生·kubernetes·k8
棒棒的唐2 天前
WSL2用npm安装的openclaw,无法正常使用openclaw gateway start启动服务的问题
前端·npm·gateway
恼书:-(空寄2 天前
K8s Ingress 七层网关 + 灰度发布 + HTTPS 实战
容器·kubernetes
不是书本的小明2 天前
ACK+ESS实现K8s节点自动扩缩容
容器·kubernetes
恼书:-(空寄2 天前
Docker Swarm + K8s 集群部署完整指南
docker·容器·kubernetes
yuanlaile2 天前
Linux Docker、Swarm、K8s分布式部署全集解析
linux·docker·kubernetes·k8s实战
观测云2 天前
Python 应用实现 APM 自动注入(Kubernetes 篇)
开发语言·python·kubernetes