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}/
相关推荐
chen_ke_hao16 分钟前
K8s 高可用集群部署
java·docker·kubernetes
Geek-Chow32 分钟前
Kubernetes HPA Behavior When Deployment Is Scaled to 0
云原生·容器·kubernetes
张忠琳11 小时前
【kubernetes】Node Feature Discovery 0.20.0-devel 源码深度解析 — 第四卷:CLI入口、工具链与全局架构总结
云原生·容器·架构·kubernetes·nvidia
汪汪大队u17 小时前
【无标题】
运维·docker·kubernetes·prometheus
云烟成雨TD21 小时前
Kubernetes 系列【20】服务:EndpointSlice 端点分片
云原生·容器·kubernetes
专注_每天进步一点点2 天前
SLB(绑定弹性公网ip)-gateway-业务pod,gateway上出现reset by peer,业务pod上没有reset by peer
服务器·tcp/ip·gateway
hj2862512 天前
K8S 核心组件与资源概念 + 带注释命令 + 实操案例版笔记
笔记·容器·kubernetes
nece0012 天前
Kubernetes v1.36.0 + Ubuntu24.04 + containerd 2.x WordPress 完整部署文档
云原生·容器·kubernetes
众人皆醒我独醉3 天前
OpenShift RBAC 与平台安全策略:比 K8s 多出来的那几道锁,每道都是为了堵一个曾经发生过的事故
面试·kubernetes
众人皆醒我独醉3 天前
为什么你的 RBAC 配了还是 403?—— 一套可以复现的排障方法论
面试·kubernetes