创建一个Kubernetes集群并安装带有sidecare自动注入的Istio。
使用你选择的语言创建Hello World应用程序,创建Docker镜像并将其推送到公共镜像仓库。
为你的容器创建Kubernetes Deployment和Service。
创建Gateway以启用到群集的HTTP(S)流量。
创建VirtualService[2],通过Gateway公开Kubernetes服务。
(可选)如果要创建多个版本应用程序,请创建DestinationRule[3]以定义可从VirtualService引用的subsets。
(可选)如果要在服务网格外部调用其他外部服务,请创建ServiceEntry[4]。
apiVersion: v1
kind: Service
metadata:
name: aspnetcore-service
labels:
app: aspnetcore
spec:
ports:
- port: 8080
name: http
selector:
app: aspnetcore
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: aspnetcore-v1
spec:
replicas: 1
template:
metadata:
labels:
app: aspnetcore
version: v1
spec:
containers:
- name: aspnetcore
image: gcr.io/istio-project-212517/hello-dotnet:v1
imagePullPolicy: Always #IfNotPresent
ports:
- containerPort: 8080
$ kubectl apply -f aspnetcore.yaml
service "aspnetcore-service" created
deployment.extensions "aspnetcore-v1" created
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: aspnetcore-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
$ kubectl apply -f aspnetcore-gateway.yaml
gateway.networking.istio.io "aspnetcore-gateway" created
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: aspnetcore-virtualservice
spec:
hosts:
- "*"
gateways:
- aspnetcore-gateway
http:
- route:
- destination:
host: aspnetcore-service
$ kubectl apply -f aspnetcore-virtualservice.yaml
virtualservice.networking.istio.io "aspnetcore-virtualservice" created
$ kubectl get svc istio-ingressgateway -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP
istio-ingressgateway LoadBalancer 10.31.247.41 35.240.XX.XXX
apiVersion: v1
kind: Service
metadata:
name: aspnetcore-service
labels:
app: aspnetcore
spec:
ports:
- port: 8080
name: http
selector:
app: aspnetcore
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: aspnetcore-v1
spec:
replicas: 1
template:
metadata:
labels:
app: aspnetcore
version: v1
spec:
containers:
- name: aspnetcore
image: gcr.io/istio-project-212517/hello-dotnet:v1
imagePullPolicy: Always #IfNotPresent
ports:
- containerPort: 8080
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: aspnetcore-v2
spec:
replicas: 1
template:
metadata:
labels:
app: aspnetcore
version: v2
spec:
containers:
- name: aspnetcore
image: gcr.io/istio-project-212517/hello-dotnet:v2
imagePullPolicy: Always #IfNotPresent
ports:
- containerPort: 8080
$ kubectl apply -f aspnetcore.yaml
service "aspnetcore-service" unchanged
deployment.extensions "aspnetcore-v1" unchanged
deployment.extensions "aspnetcore-v2" created
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: aspnetcore-destinationrule
spec:
host: aspnetcore-service
trafficPolicy:
tls:
mode: ISTIO_MUTUAL
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
$ kubectl apply -f aspnetcore-destinationrule.yaml
destinationrule.networking.istio.io "aspnetcore-destinationrule" created
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: aspnetcore-virtualservice
spec:
hosts:
- "*"
gateways:
- aspnetcore-gateway
http:
- route:
- destination:
host: aspnetcore-service
subset: v2
$ kubectl apply -f aspnetcore-virtualservice.yaml
virtualservice.networking.istio.io "aspnetcore-virtualservice" configured
https://codelabs.developers.google.com/codelabs/cloud-istio-aspnetcore-part1
https://codelabs.developers.google.com/codelabs/cloud-istio-aspnetcore-part2
https://github.com/istio/istio/tree/master/samples
https://istio.io/docs/reference/config/istio.networking.v1alpha3/#VirtualService
https://istio.io/docs/reference/config/istio.networking.v1alpha3/#DestinationRule
https://istio.io/docs/reference/config/istio.networking.v1alpha3/#ServiceEntry