前提条件
- 已开通云容器引擎,至少有一个云容器引擎实例。产品入口:云容器引擎。
- 开通天翼云服务网格实例。
操作步骤
创建命名空间
首先到云容器引擎控制台找到当前添加到服务网格的云容器引擎集群,创建测试应用部署的sample命名空间,同时给命名空间打上istio-injection: enabled的标签以保证该命名空间下的pod会被注入sidecar。
部署应用
使用如下yaml部署我们的bookinfo应用,注意根据当前集群所在的资源池替换镜像的地址(当前云容器引擎实例在华东1资源池);如果您想要把演示应用部署到其他namespace也可以修改yaml里面的namespace字段实现,示例yaml如下:
apiVersion: v1
kind: Service
metadata:
name: details
labels:
withServiceMesh: "true"
workloadKind: Deployment
workloadName: details-v1
spec:
ports:
- port: 9080
targetPort: 9080
name: http
selector:
app: details
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: details-v1
labels:
withServiceMesh: "true"
spec:
replicas: 1
selector:
matchLabels:
name: details-v1
template:
metadata:
labels:
app: details
version: v1
name: details-v1
source: CCSE
csmAutoEnable: "on"
"sidecar.istio.io/inject": "true"
annotations:
"sidecar.istio.io/inject": "true"
spec:
containers:
- name: details
image: 'registry-vpc-crs-huadong1.cnsp-internal.ctyun.cn/library/istio-examples-bookinfo-details-v1:1.16.2'
imagePullPolicy: IfNotPresent
resources:
limits:
cpu: "200m"
memory: "256Mi"
requests:
cpu: "50m"
memory: "64Mi"
---
apiVersion: v1
kind: Service
metadata:
name: ratings
labels:
withServiceMesh: "true"
workloadKind: Deployment
workloadName: ratings-v1
spec:
ports:
- port: 9080
targetPort: 9080
name: http
selector:
app: ratings
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: ratings-v1
labels:
withServiceMesh: "true"
spec:
replicas: 1
selector:
matchLabels:
name: ratings-v1
template:
metadata:
labels:
app: ratings
version: v1
name: ratings-v1
source: CCSE
"sidecar.istio.io/inject": "true"
csmAutoEnable: "on"
annotations:
"sidecar.istio.io/inject": "true"
spec:
containers:
- name: ratings
image: 'registry-vpc-crs-huadong1.cnsp-internal.ctyun.cn/library/istio-examples-bookinfo-ratings-v1:1.16.2'
imagePullPolicy: IfNotPresent
resources:
limits:
cpu: "200m"
memory: "256Mi"
requests:
cpu: "50m"
memory: "64Mi"
---
apiVersion: v1
kind: Service
metadata:
name: reviews
labels:
withServiceMesh: "true"
workloadKind: Deployment
workloadName: reviews-v1
spec:
ports:
- port: 9080
targetPort: 9080
name: http
selector:
app: reviews
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: reviews-v1
labels:
withServiceMesh: "true"
spec:
replicas: 1
selector:
matchLabels:
name: reviews-v1
template:
metadata:
labels:
app: reviews
version: v1
name: reviews-v1
source: CCSE
"sidecar.istio.io/inject": "true"
csmAutoEnable: "on"
annotations:
"sidecar.istio.io/inject": "true"
spec:
containers:
- name: reviews
image: 'registry-vpc-crs-huadong1.cnsp-internal.ctyun.cn/library/istio-examples-bookinfo-reviews-v1:1.16.2'
imagePullPolicy: IfNotPresent
env:
- name: LOG_DIR
value: "/tmp/logs"
volumeMounts:
- name: tmp
mountPath: /tmp
- name: wlp-output
mountPath: /opt/ibm/wlp/output
volumes:
- name: wlp-output
emptyDir: {}
- name: tmp
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: productpage
labels:
withServiceMesh: "true"
workloadKind: Deployment
workloadName: productpage-v1
spec:
ports:
- port: 9080
targetPort: 9080
name: http
selector:
app: productpage
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: productpage-v1
labels:
withServiceMesh: "true"
spec:
replicas: 1
selector:
matchLabels:
name: productpage-v1
template:
metadata:
labels:
app: productpage
version: v1
name: productpage-v1
source: CCSE
"sidecar.istio.io/inject": "true"
csmAutoEnable: "on"
annotations:
"sidecar.istio.io/inject": "true"
spec:
containers:
- name: productpage
image: 'registry-vpc-crs-huadong1.cnsp-internal.ctyun.cn/library/istio-examples-bookinfo-productpage-v1:1.16.2'
imagePullPolicy: IfNotPresent
resources:
limits:
cpu: "200m"
memory: "256Mi"
requests:
cpu: "50m"
memory: "64Mi"
volumeMounts:
- name: tmp
mountPath: /tmp
volumes:
- name: tmp
emptyDir: {}
---
在云容器引擎控制台选择我们要部署的sample命名空间,通过工作负载->无状态->新增yaml,依次部署上面的deployment;
通过网络->服务->新增yaml依次部署上面的Service填入我们准备的yaml文件,保存即可;
部署完成后,可以在工作负载->无状态列表里看到bookinfo相关的部署信息,在网络->Service菜单下可以看到刚部署的Service列表。