kubectl apply -f https://raw.githubusercontent.com/knative/serving/master/third_party/istio-1.0.2/istio-crds.yaml
kubectl apply -f https://raw.githubusercontent.com/knative/serving/master/third_party/istio-1.0.2/istio.yaml
Deployment
及其对应的Service
# Create Deployments
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-a
spec:
selector:
matchLabels:
app: a
replicas: 3
template:
metadata:
labels:
app: a
spec:
containers:
- name: print
image: gcr.io/invertible-lens-220304/print
env:
- name: TEXT_TO_PRINT
value: "AAAAAAAAAAAAAAAAAAAA"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-b
spec:
selector:
matchLabels:
app: b
replicas: 3
template:
metadata:
labels:
app: b
spec:
containers:
- name: print
image: gcr.io/invertible-lens-220304/print
env:
- name: TEXT_TO_PRINT
value: "BBBBBBBBBBBBBBBBBBBB"
EOF
# Create Services
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
name: service-a
spec:
ports:
- port: 80
protocol: TCP
selector:
app: a
---
apiVersion: v1
kind: Service
metadata:
name: service-b
spec:
ports:
- port: 80
protocol: TCP
selector:
app: b
EOF
Gateway
及其对应的NodePorts # Create gateways
cat <<EOF | kubectl apply -f -
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: gateway-a
namespace: istio-system
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 3001
name: http
protocol: HTTP
hosts:
- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: gateway-b
namespace: istio-system
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 3002
name: http
protocol: HTTP
hosts:
- "*"
EOF
# Add ports to the istio-ingressgateway service
kubectl patch service istio-ingressgateway -n istio-system --type json --patch "$(cat <<EOF
[{
"op" : "add" ,
"path" : "/spec/ports/-" ,
"value" : {
"name" : "node-port-1",
"nodePort" : 30001,
"port": 3001,
"protocol": "TCP",
"targetPort": 3001
}
}, {
"op" : "add" ,
"path" : "/spec/ports/-" ,
"value" : {
"name" : "node-port-2",
"nodePort" : 30002,
"port": 3002,
"protocol": "TCP",
"targetPort": 3002
}
}]
EOF)"
VirtualService
Gateway
个
cat <<EOF | kubectl apply -f -
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: virtualservice-a
namespace: istio-system
spec:
gateways:
- gateway-a
hosts:
- example.com
http:
- match:
- authority:
exact: example.com
route:
- destination:
host: service-a.default.svc.cluster.local
port:
number: 80
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: virtualservice-b
namespace: istio-system
spec:
gateways:
- gateway-b
hosts:
- example.com
http:
- match:
- authority:
exact: example.com
route:
- destination:
host: service-b.default.svc.cluster.local
port:
number: 80
EOF
NODE_IP=$(kubectl get nodes -o jsonpath="{.items[0].status.addresses[1].address}")
curl $NODE_IP:30001 -H "Host: example.com"
# Result: AAAAAAAAAAAAAAAAAAAA
curl $NODE_IP:30002 -H "Host: example.com"
# Result: AAAAAAAAAAAAAAAAAAAA
kubectl delete virtualservice virtualservice-a -n istio-system
curl $NODE_IP:30001 -H "Host: example.com"
# Result: BBBBBBBBBBBBBBBBBBBB
curl $NODE_IP:30002 -H "Host: example.com"
# Result: BBBBBBBBBBBBBBBBBBBB
由于30001
绑定到gateway-a
指向virtualservice-a
的{{1}},并且service-a
绑定到30002
具有{{ 1}}指向gateway-b
,我希望结果是:
virtualservice-b
发生了什么事,如何使它正常工作?
P.S。
service-b
部署是可能的,但仅一个部署我就能达到相同的结果吗? curl $NODE_IP:30001 -H "Host: example.com"
# Result: AAAAAAAAAAAAAAAAAAAA
curl $NODE_IP:30002 -H "Host: example.com"
# Result: BBBBBBBBBBBBBBBBBBBB
和一个istio-ingressgateway
,然后在VirtualService
中设置Gateway
,但这仍然不是我想要的。我要在同一个port
(docker.io/istio/proxyv2:1.0.2)部署的不同端口上具有两个网关,并分别具有它们自己的虚拟服务,而不互相影响。有可能吗?