我尝试使用Helm将现有应用程序安装到【已存在的】Azure Kubernetes Service (AKS)中
总结
我根据这篇文章作为参考,总结了在AKS上启动ACR中的容器应用程序(RabbitMQ)的步骤,以帮助我更好地理解Helm v3。
本地环境
macOS 平台上的最新版本是 Big Sur 11.3 。
Python 的最新版本是 3.8.3 。
Helm 的最新版本是 3.6.3 。
前期准备
-
- 根据这篇文章的参考内容,已经建立了AKS和ACR,并确认了在AKS集群上运行节点。
根据这篇文章的参考内容,已经将容器应用程序推送到ACR上。
根据这篇文章中的”Helm准备”部分,已经完成了准备工作。
创建Helm Chart。
获取ACR登录服务器地址
$ az acr list --resource-group $ACR_RES_GROUP --query "[].{acrLoginServer:loginServer}" --output tsv
acr0ituru.azurecr.io
Helm Chart 的搜索
由于要使用已注册的ACR中的RabbitMQ容器应用程序,因此需要搜索rabbitmq。
$ helm search repo rabbitmq
NAME CHART VERSION APP VERSION DESCRIPTION
bitnami-azure/rabbitmq 8.19.1 3.8.19 Open source message broker software that implem...
stable/prometheus-rabbitmq-exporter 0.5.6 v0.29.0 DEPRECATED Rabbitmq metrics exporter for promet...
stable/rabbitmq 6.18.2 3.8.2 DEPRECATED Open source message broker software ...
stable/rabbitmq-ha 1.47.1 3.8.7 DEPRECATED - Highly available RabbitMQ cluster,...
作为 Helm Chart 的源。
$ helm pull bitnami-azure/rabbitmq
$ tar zxf rabbitmq-8.19.1.tgz
$ tree -a
.
├── rabbitmq
│ ├── .helmignore
│ ├── Chart.lock
│ ├── Chart.yaml
│ ├── README.md
│ ├── charts
│ │ └── common
│ │ ├── .helmignore
│ │ ├── Chart.yaml
│ │ ├── README.md
│ │ ├── templates
│ │ │ ├── _affinities.tpl
│ │ │ ├── _capabilities.tpl
│ │ │ ├── _errors.tpl
│ │ │ ├── _images.tpl
│ │ │ ├── _ingress.tpl
│ │ │ ├── _labels.tpl
│ │ │ ├── _names.tpl
│ │ │ ├── _secrets.tpl
│ │ │ ├── _storage.tpl
│ │ │ ├── _tplvalues.tpl
│ │ │ ├── _utils.tpl
│ │ │ ├── _warnings.tpl
│ │ │ └── validations
│ │ │ ├── _cassandra.tpl
│ │ │ ├── _mariadb.tpl
│ │ │ ├── _mongodb.tpl
│ │ │ ├── _postgresql.tpl
│ │ │ ├── _redis.tpl
│ │ │ └── _validations.tpl
│ │ └── values.yaml
│ ├── ci
│ │ ├── default-values.yaml
│ │ └── tolerations-values.yaml
│ ├── templates
│ │ ├── NOTES.txt
│ │ ├── _helpers.tpl
│ │ ├── configuration.yaml
│ │ ├── extra-list.yaml
│ │ ├── ingress.yaml
│ │ ├── networkpolicy.yaml
│ │ ├── pdb.yaml
│ │ ├── prometheusrule.yaml
│ │ ├── role.yaml
│ │ ├── rolebinding.yaml
│ │ ├── secrets.yaml
│ │ ├── serviceaccount.yaml
│ │ ├── servicemonitor.yaml
│ │ ├── statefulset.yaml
│ │ ├── svc-headless.yaml
│ │ ├── svc.yaml
│ │ └── tls-secrets.yaml
│ ├── values.schema.json
│ └── values.yaml
└── rabbitmq-8.19.1.tgz
编辑 values.yaml 文件
我将会编辑上述目录中的 values.yaml 文件中的以下部分。
global:
# imageRegistry: acr0ituru.azurecr.io
imageRegistry: acr0ituru.azurecr.io
image:
# registry: docker.io
# repository: bitnami/rabbitmq
# tag: 3.8.19-debian-10-r0
registry: acr0ituru.azurecr.io
repository: rabbitmq
tag: 3.8.17
编辑NOTES.txt文件
我将编辑位于上述目录中的NOTES.txt文件中的以下部分。
Credentials:
Username : guest
Password : guest
编辑 Chart.yaml 文件。
我們將編輯上述目錄中的Chart.yaml文件的以下部分(將現有應用程序的RabbitMQ版本更改為所需版本)。
# appVersion: 3.8.19
appVersion: 3.8.17
应用程序的部署
创建命名空间
$ kubectl create namespace helm-mq02
模拟运行
$ helm install mqtest02 ./rabbitmq --namespace helm-mq02 --dry-run
部署
$ helm install mqtest02 ./rabbitmq --namespace helm-mq02
NAME: mqtest02
LAST DEPLOYED: Fri Aug 6 13:33:44 2021
NAMESPACE: helm-mq02
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
** Please be patient while the chart is being deployed **
Credentials:
Username : guest
Password : guest
Note that the credentials are saved in persistent volume claims and will not be changed upon upgrade or reinstallation unless the persistent volume claim has been deleted. If this is not the first installation of this chart, the credentials may not be valid.
This is applicable when no passwords are set and therefore the random password is autogenerated. In case of using a fixed password, you should specify it when upgrading.
More information about the credentials may be found at https://docs.bitnami.com/general/how-to/troubleshoot-helm-chart-issues/#credential-errors-while-upgrading-chart-releases.
RabbitMQ can be accessed within the cluster on port at mqtest02-rabbitmq.helm-mq02.svc.
To access for outside the cluster, perform the following steps:
To Access the RabbitMQ AMQP port:
echo "URL : amqp://127.0.0.1:5672/"
kubectl port-forward --namespace helm-mq02 svc/mqtest02-rabbitmq 5672:5672
To Access the RabbitMQ Management interface:
echo "URL : http://127.0.0.1:15672/"
kubectl port-forward --namespace helm-mq02 svc/mqtest02-rabbitmq 15672:15672
显示已安装的图表
$ helm list -n helm-mq02
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mqtest02 helm-mq02 1 2021-08-06 13:33:44.284954 +0900 JST deployed rabbitmq-8.19.1 3.8.17
确认Pod
$ kubectl get pod -n helm-mq02
NAME READY STATUS RESTARTS AGE
mqtest02-rabbitmq-0 1/1 Running 0 2m17s
确认其他资源
$ kubectl get deployment -n helm-mq02
$ kubectl get service -n helm-mq02
$ kubectl get configmap -n helm-mq02
应用程序的运行确认
在NOTES中确认步骤
上述的执行结果的NOTES部分包含了基本的使用方法。
$ helm install mqtest01 bitnami-azure/rabbitmq --namespace helm-mq01
NOTES:<抜粋>
To Access the RabbitMQ AMQP port:
echo "URL : amqp://127.0.0.1:5672/"
kubectl port-forward --namespace helm-mq01 svc/mqtest01-rabbitmq 5672:5672
To Access the RabbitMQ Management interface:
echo "URL : http://127.0.0.1:15672/"
kubectl port-forward --namespace helm-mq01 svc/mqtest01-rabbitmq 15672:15672
筆記 执行步骤
端口转发设置
$ kubectl port-forward --namespace helm-mq02 svc/mqtest02-rabbitmq 15672:15672
Forwarding from 127.0.0.1:15672 -> 15672
Forwarding from [::1]:15672 -> 15672
如果要停止端口转发,请按Ctrl+C
访问应用程序

卸载应用程序
$ helm uninstall mqtest02 -n helm-mq02
or
$ helm delete mqtest02 -n helm-mq02
release "mqtest02" uninstalled
删除命名空间
$ kubectl delete namespace helm-mq02
namespace "helm-mq02" deleted
总结
我已经通过使用Helm v3并将其应用于Helm repository的chart base,确认了在AKS上运行现有的容器应用程序。
额外篇
如果只是简单的验证操作,可以更方便一些。
将 values.yaml 复制到当前目录
$ cp rabbitmq/values.yaml .
$ ls -l
drwxr-xr-x 7 hoge staff 224 8 6 00:58 ./
drwxr-xr-x 7 hoge staff 224 8 4 01:18 ../
drwxr-xr-x 11 hoge staff 352 8 6 00:30 rabbitmq/
-rw-r--r-- 1 hoge staff 47260 8 6 00:29 rabbitmq-8.19.1.tgz
-rw-r--r-- 1 hoge staff 42656 8 6 00:58 values.yaml
部署
$ helm install -f values.yaml mqtest02 bitnami-azure/rabbitmq --namespace helm-mq02
参考资料
我参考了以下信息,非常感谢。
推荐Helm v3
Helm已成为事实上的Kubernetes部署工具,适用于初学者。