1. 首先在集群内启动一个nginx服务
$ cat ./nginx.yaml
$ cat ./nginx.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
type: ClusterIP
selector:
app: nginx
ports:
- port: 80
targetPort: 80
name: http-nginx
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-v1
spec:
replicas: 1
template:
metadata:
labels:
app: nginx
version: v1
spec:
nodeSelector:
kubernetes.io/hostname: 192.168.5.86
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
2. 配置gateway
$ cat ./nginx-gateway.yaml
$ cat ./nginx-gateway.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: nginx-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "h1.example.com"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: nginx
spec:
hosts:
- "h1.example.com"
gateways:
- nginx-gateway
http:
- match:
- uri:
exact: /
route:
- destination:
host: nginx
port:
number: 80
3. 访问:
$ curl http://h1.example.com/