部署bookinfo應用到CSM實例
更新時間 2025-02-21 09:57:18
最近更新時間: 2025-02-21 09:57:18
分享文章
本章節介紹如何部署bookinfo應用到CSM實例
前提條件
- 已開通云容器引擎,至少有一個云容器引擎實例。產品入口:云容器引擎。
- 開通天翼云服務網格實例。
操作步驟
創建命名空間
首先到云容器引擎控制臺找到當前添加到服務網格的云容器引擎集群,創建測試應用部署的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.daliqc.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.daliqc.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.daliqc.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.daliqc.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列表。