新增帶有 Istio Sidecar 的部署和服務
注意
Rancher-Istio 將在 Rancher v2.12.0 中被棄用;請使用 SUSE Rancher Application Collection 版本的 Istio 以增強安全性(包含在 SUSE Rancher Prime 訂閱中)。
詳細資訊可以在此公告中找到。
先決條件:
若要為工作負載啟用 Istio,叢集和命名空間必須安裝 Istio 應用程式。
在命名空間中啟用 Istio 只會為新工作負載啟用自動 sidecar 注入。若要為現有工作負載啟用 Envoy sidecar,您需要為每個工作負載手動啟用它。
若要在命名空間中的現有工作負載上注入 Istio sidecar:
- 在左上角,點擊 ☰ > Cluster Management。
- 在 Clusters 頁面上,前往您想要查看視覺化的叢集並點擊 Explore。
- 點擊 Workload。
- 前往您想要注入 Istio sidecar 的工作負載並點擊 ⋮ > Redeploy。當工作負載重新部署時,它將自動注入 Envoy sidecar。
等待幾分鐘讓工作負載升級以擁有 istio sidecar。點擊它並前往 Containers 區段。您應該能夠在原始工作負載旁邊看到 istio-proxy。這意味著工作負載已啟用 Istio sidecar。Istio 正在為 sidecar envoy 執行所有佈線。現在如果您在 yaml 中啟用它們,Istio 可以自動執行所有功能。
新增部署和服務
在您的命名空間中新增新 Deployments 有幾種方法:
- 點擊 ☰ > Cluster Management。
- 前往您建立的叢集並點擊 Explore。
- 點擊 Workload。
- 點擊 Create。
- 點擊 Deployment。
- 填寫表單,或點擊 Edit as Yaml。
- 點擊 Create。
若要將 Service 新增到您的命名空間:
- 點擊 ☰ > Cluster Management。
- 前往您建立的叢集並點擊 Explore。
- 點擊 Service Discovery > Services。
- 點擊 Create。
- 選擇您想要的服務類型。
- 填寫表單,或點擊 Edit as Yaml。
- 點擊 Create。
您還可以使用 kubectl shell 建立部署和服務
- 如果您的檔案儲存在叢集本地,請執行
kubectl create -f <服務/部署檔案名稱>.yaml - 或執行
cat<< EOF | kubectl apply -f -,將檔案內容貼到終端機中,然後執行EOF以完成命令。
部署和服務範例
接下來我們為 Istio 文件中的 BookInfo 應用程式的範例部署和服務新增 Kubernetes 資源。
- 點擊 ☰ > Cluster Management。
- 前往您建立的叢集並點擊 Explore。
- 在頂部導覽列中,開啟 kubectl shell。
- 執行
cat<< EOF | kubectl apply -f - - 將下面的資源複製到 shell 中。
- 執行
EOF
這將從 Istio 的範例 BookInfo 應用程式設定以下範例資源:
Details 服務和部署:
- 一個
details服務 - 用於
bookinfo-details的 ServiceAccount - 一個
details-v1部署
Ratings 服務和部署:
- 一個
ratings服務 - 用於
bookinfo-ratings的 ServiceAccount - 一個
ratings-v1部署
Reviews 服務和部署(三個版本):
- 一個
reviews服務 - 用於
bookinfo-reviews的 ServiceAccount - 一個
reviews-v1部署 - 一個
reviews-v2部署 - 一個
reviews-v3部署
Productpage 服務和部署:
這是應用程式的主頁,可以從網頁瀏覽器中看到。其他服務將從此頁面呼叫。
- 一個
productpage服務 - 用於
bookinfo-productpage的 ServiceAccount - 一個
productpage-v1部署
資源 YAML
# Copyright 2017 Istio Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##################################################################################################
# Details service
##################################################################################################
apiVersion: v1
kind: Service
metadata:
name: details
labels:
app: details
service: details
spec:
ports:
- port: 9080
name: http
selector:
app: details
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: bookinfo-details
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: details-v1
labels:
app: details
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: details
version: v1
template:
metadata:
labels:
app: details
version: v1
spec:
serviceAccountName: bookinfo-details
containers:
- name: details
image: docker.io/istio/examples-bookinfo-details-v1:1.15.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9080
---
##################################################################################################
# Ratings service
##################################################################################################
apiVersion: v1
kind: Service
metadata:
name: ratings
labels:
app: ratings
service: ratings
spec:
ports:
- port: 9080
name: http
selector:
app: ratings
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: bookinfo-ratings
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: ratings-v1
labels:
app: ratings
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: ratings
version: v1
template:
metadata:
labels:
app: ratings
version: v1
spec:
serviceAccountName: bookinfo-ratings
containers:
- name: ratings
image: docker.io/istio/examples-bookinfo-ratings-v1:1.15.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9080
---
##################################################################################################
# Reviews service
##################################################################################################
apiVersion: v1
kind: Service
metadata:
name: reviews
labels:
app: reviews
service: reviews
spec:
ports:
- port: 9080
name: http
selector:
app: reviews
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: bookinfo-reviews
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: reviews-v1
labels:
app: reviews
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: reviews
version: v1
template:
metadata:
labels:
app: reviews
version: v1
spec:
serviceAccountName: bookinfo-reviews
containers:
- name: reviews
image: docker.io/istio/examples-bookinfo-reviews-v1:1.15.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: reviews-v2
labels:
app: reviews
version: v2
spec:
replicas: 1
selector:
matchLabels:
app: reviews
version: v2
template:
metadata:
labels:
app: reviews
version: v2
spec:
serviceAccountName: bookinfo-reviews
containers:
- name: reviews
image: docker.io/istio/examples-bookinfo-reviews-v2:1.15.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9080
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: reviews-v3
labels:
app: reviews
version: v3
spec:
replicas: 1
selector:
matchLabels:
app: reviews
version: v3
template:
metadata:
labels:
app: reviews
version: v3
spec:
serviceAccountName: bookinfo-reviews
containers:
- name: reviews
image: docker.io/istio/examples-bookinfo-reviews-v3:1.15.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9080
---
##################################################################################################
# Productpage services
##################################################################################################
apiVersion: v1
kind: Service
metadata:
name: productpage
labels:
app: productpage
service: productpage
spec:
ports:
- port: 9080
name: http
selector:
app: productpage
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: bookinfo-productpage
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: productpage-v1
labels:
app: productpage
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: productpage
version: v1
template:
metadata:
labels:
app: productpage
version: v1
spec:
serviceAccountName: bookinfo-productpage
containers:
- name: productpage
image: docker.io/istio/examples-bookinfo-productpage-v1:1.15.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9080
---