创建3个dep
depv1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: versionv1
namespace: lizhe
spec:
replicas: 1
selector:
matchLabels:
app: nginx
version: v1
template:
metadata:
labels:
app: nginx
version: v1
spec:
containers:
- name: versionv1
image: libaibai/version:v1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
name: http
protocol: TCP
depv2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: versionv2
namespace: lizhe
spec:
replicas: 1
selector:
matchLabels:
app: nginx
version: v2
template:
metadata:
labels:
app: nginx
version: v2
spec:
containers:
- name: versionv2
image: libaibai/version:v2
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
name: http
protocol: TCP
depv3.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: versionv3
namespace: lizhe
spec:
replicas: 1
selector:
matchLabels:
app: nginx
version: v3
template:
metadata:
labels:
app: nginx
version: v3
spec:
containers:
- name: versionv3
image: libaibai/version:v3
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
name: http
protocol: TCP
svc.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: lizhe
labels:
app: nginx
spec:
ports:
- port: 80
name: http
selector:
app: nginx
为了测试我会在这里再启动一个 nginx
需要特别注意的是,这个nginx也需要注入istio,否则无法以 nginx-service 做为路径, 你可能已经注意到了,这里不是使用的标准 Kubernetes DNS格式
然后我们试着把流量单独导向 v2
dr.yaml
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: nginx-desrule
namespace: lizhe
spec:
host: nginx-service
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
- name: v3
labels:
version: v3
vs.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: nginx-default-v2
namespace: lizhe
spec:
hosts:
- nginx-service
http:
- route:
- destination:
host: nginx-service
subset: v2
Istio已用新的Gateway
和VirtualServices
资源替换了熟悉的Ingress
资源。它们协同工作,将流量路由到网格中。在网格内部,不需要Gateway
,因为服务可以通过集群本地服务名称相互访问。