在GCP的Kubernetes上安裝dapr

2023-02-03 15:00:18

1 簡介

我們之前使用了dapr的本地託管模式,但在生產中我們一般使用Kubernetes託管,本文介紹如何在GKE(GCP Kubernetes)安裝dapr。

相關文章:

2 安裝GKE

我們直接在網頁上安裝GKE,我們安裝的是Autopilot模式的GKE,如下:

點選建立,等一段時間後就會建立成功了。

檢查 GKE狀態

需要安裝以下gcloud外掛:

$ gcloud components install gke-gcloud-auth-plugin

獲取許可權讓kubectl可以存取:

$ gcloud container clusters get-credentials pkslow-autopilot --zone us-west1

檢視node節點,說明正常啟動了:

$ kubectl get nodes
NAME                                              STATUS   ROLES    AGE   VERSION
gk3-pkslow-autopilot-default-pool-1bb48cfc-6jzc   Ready    <none>   64m   v1.23.8-gke.1900
gk3-pkslow-autopilot-default-pool-33b02029-zz1d   Ready    <none>   64m   v1.23.8-gke.1900

安裝dapr

建立namespace:

$ kubectl create ns pkslow-dapr
namespace/pkslow-dapr created

我們用helm工具來安裝,先新增倉庫:

$ helm repo add dapr https://dapr.github.io/helm-charts/
"dapr" has been added to your repositories


$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "dapr" chart repository
...Successfully got an update from the "stable" chart repository
...Successfully got an update from the "k8ssandra" chart repository
...Successfully got an update from the "azure" chart repository
Update Complete. ⎈ Happy Helming!⎈ 

通過下面命令安裝dapr如下:

$ helm install dapr dapr/dapr --namespace pkslow-dapr
NAME: dapr
LAST DEPLOYED: Wed Nov  9 22:16:51 2022
NAMESPACE: pkslow-dapr
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Thank you for installing Dapr: High-performance, lightweight serverless runtime for cloud and edge

Your release is named dapr.

To get started with Dapr, we recommend using our quickstarts:
https://github.com/dapr/quickstarts

For more information on running Dapr, visit:
https://dapr.io

過一段時間後,Pod啟動完成,然後檢視狀態如下:

$ kubectl get pods -n pkslow-dapr
NAME                                     READY   STATUS    RESTARTS   AGE
dapr-dashboard-68d9d6c58-7nwqm           1/1     Running   0          2m58s
dapr-operator-5d44bd648d-6wlbf           1/1     Running   0          2m58s
dapr-placement-server-0                  1/1     Running   0          2m57s
dapr-sentry-67d76bc57-tp67f              1/1     Running   0          2m58s
dapr-sidecar-injector-84f85f5699-scz4c   1/1     Running   0          2m58s

檢視dapr的Dashboard:

$ dapr dashboard -k -n pkslow-dapr
W1109 22:21:50.051562   52857 gcp.go:120] WARNING: the gcp auth plugin is deprecated in v1.22+, unavailable in v1.25+; use gcloud instead.
To learn more, consult https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke
ℹ️  Dapr dashboard found in namespace:	pkslow-dapr
ℹ️  Dapr dashboard available at:	http://localhost:8080

開啟網頁:

控制面板:

總結

至此,我們在GKE成功地安裝了dapr。


References:

用Helm部署Kubernetes應用,支援多環境部署與版本回滾

GCP常用命令(gcloud、gsutil)

通過gcloud建立Google Kubernetes Engine(GKE)並通過kubectl存取