本文作者:丁辉
使用Istio开启对外访问
Istio开启对外访问
部署基础服务
部署 Nginx 资源
1
2kubectl apply -f https://gitee.com/offends/Kubernetes/raw/main/File/Yaml/nginx-deployment.yaml
kubectl apply -f https://gitee.com/offends/Kubernetes/raw/main/File/Yaml/nginx-deployment-svc.yaml查看部署情况
1
kubectl get deploy,svc
配置 Istio 对外访问
部署 Nginx Gateway 资源
HTTP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17cat <<EOF | kubectl apply -f -
apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
name: nginx-gateway
namespace: default
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- '*'
EOFHTTPS
创建证书 Secret 资源
1
kubectl create secret tls demo-tls --cert=server.crt --key=server.key -n istio-system
创建 Gateway 资源
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20cat <<EOF | kubectl apply -f -
apiVersion: networking.istio.io/v1
kind: Gateway
metadata:
name: nginx-gateway
namespace: default
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 443
name: https
protocol: HTTPS
hosts:
- example.com # 替换为你的域名
tls:
mode: SIMPLE
credentialName: example-tls # 替换为你的证书,这个 secret 必须在 istio-system 命名空间
EOF
部署 Nginx VirtualService 资源
HTTP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22cat <<EOF | kubectl apply -f -
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: nginx-virtualservice
namespace: default
spec:
hosts:
- '*'
gateways:
- nginx-gateway
http:
- match:
- uri:
prefix: /
port: 80
route:
- destination:
host: nginx-service.default.svc.cluster.local
port:
number: 80
EOFHTTPS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22cat <<EOF | kubectl apply -f -
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: nginx-virtualservice
namespace: default
spec:
hosts:
- example.com # 替换为你的域名
gateways:
- nginx-gateway
http:
- match:
- uri:
prefix: /
port: 443
route:
- destination:
host: nginx-service.default.svc.cluster.local
port:
number: 80
EOF
访问测试
1
kubectl get svc istio-ingressgateway -n istio-system
通过
域名或IP:80访问
要是这篇文章为您解了惑、带来了帮助,不妨用小小的打赏来支持下我的创作吧,您的鼓励就是我持续分享的最大动力哦,感谢您啦!
- 本文链接: https://blog.offends.cn/Kubernetes/网关/Istio/使用Istio开启对外访问.html
- 版权声明: 本博客所有文章除特别声明外,均默认采用 CC BY-NC-SA 4.0 许可协议。