Kubernetes Helm

Posted by Vito on January 27, 2024

Install

1
2
3
4
5
6
[zc@k8s-master1 ~]$ cd software/
[zc@k8s-master1 software]$ wget https://get.helm.sh/helm-v3.13.3-linux-amd64.tar.gz
[zc@k8s-master1 software]$ sudo cp linux-amd64/helm /usr/local/bin/

[zc@k8s-master1 software]$ helm version
version.BuildInfo{Version:"v3.13.3", GitCommit:"c8b948945e52abba22ff885446a1486cb5fd3474", GitTreeState:"clean", GoVersion:"go1.20.11"}

helm repo

helm repo add 添加新的仓库

1
2
3
4
5
6
7
8
[root@k8s-master1 ~]# helm repo add brigade https://brigadecore.github.io/charts
"brigade" has been added to your repositories

[root@k8s-master1 ~]# helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories

[root@k8s-master1 ~]# helm repo add azure http://mirror.azure.cn/kubernetes/charts
"azure" has been added to your repositories

helm repo list 查看配置的仓库

1
2
3
4
5
[root@k8s-master1 ~]# helm repo list
NAME   	URL                                     
brigade	https://brigadecore.github.io/charts    
bitnami	https://charts.bitnami.com/bitnami      
azure  	http://mirror.azure.cn/kubernetes/charts

helm repo remove 移除仓库

1
2
[root@k8s-master1 ~]# helm repo remove brigade
"brigade" has been removed from your repositories

helm search hub

1
2
3
4
5
6
[root@k8s-master1 ~]# helm search hub wordpress
URL                                               	CHART VERSION	APP VERSION        	DESCRIPTION                                       
https://artifacthub.io/packages/helm/wordpress-...	1.0.2        	1.0.0              	A Helm chart for deploying Wordpress+Mariadb st...
https://artifacthub.io/packages/helm/kube-wordp...	0.1.0        	1.1                	this is my wordpress package                      
https://artifacthub.io/packages/helm/truecharts...	4.0.5        	6.4.2              	The WordPress rich content management system ca...
https://artifacthub.io/packages/helm/shubham-wo...	0.1.0        	1.16.0             	A Helm chart for Kubernetes

helm search repo

  • 从自行添加(使用 helm repo add)到本地 helm 客户端中的仓库中进行查找。该命令基于本地数据进行搜索,无需连接互联网。
1
2
3
4
5
6
7
8
[root@k8s-master1 ~]# helm search repo brigade
NAME                        	CHART VERSION	APP VERSION	DESCRIPTION                                       
brigade/brigade             	1.10.0       	v1.5.0     	Brigade provides event-driven scripting of Kube...
brigade/brigade-github-app  	0.8.0        	v0.4.1     	The Brigade GitHub App, an advanced gateway for...
brigade/brigade-github-oauth	0.4.0        	v0.20.0    	The legacy OAuth GitHub Gateway for Brigade       
brigade/brigade-k8s-gateway 	0.3.0        	           	A Helm chart for Kubernetes                       
brigade/brigade-project     	1.1.0        	v1.0.0     	Create a Brigade project                          
brigade/kashti              	0.7.0        	v0.4.0     	A Helm chart for Kubernetes

helm pull 将 chart 拉取到本地当前目录

1
2
3
4
5
6
7
8
9
10
[root@k8s-master1 ~]# mkdir brigade
[root@k8s-master1 ~]# cd brigade
[root@k8s-master1 brigade]# helm pull brigade/brigade
[root@k8s-master1 brigade]# ls
brigade-1.10.0.tgz
[root@k8s-master1 brigade]# tar -zxf brigade-1.10.0.tgz 
[root@k8s-master1 brigade]# ls
brigade  brigade-1.10.0.tgz
[root@k8s-master1 brigade]# ls brigade
charts  Chart.yaml  requirements.lock  requirements.yaml  templates  values.yaml

helm install

  • helm install 自定义的release名字 chart的名字
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
[root@k8s-master1 ~]# helm search repo redis
NAME                           	CHART VERSION	APP VERSION	DESCRIPTION                                       
azure/prometheus-redis-exporter	3.5.1        	1.3.4      	DEPRECATED Prometheus exporter for Redis metrics  
azure/redis                    	10.5.7       	5.0.7      	DEPRECATED Open source, advanced key-value stor...
azure/redis-ha                 	4.4.6        	5.0.6      	DEPRECATED - Highly available Kubernetes implem...
bitnami/redis                  	18.6.1       	7.2.3      	Redis(R) is an open source, advanced key-value ...
bitnami/redis-cluster          	9.1.4        	7.2.3      	Redis(R) is an open source, scalable, distribut...
azure/sensu                    	0.2.5        	0.28       	DEPRECATED Sensu monitoring framework backed by...

# 查看安装说明
[root@k8s-master1 ~]# helm show readme bitnami/redis

[root@k8s-master1 ~]# kubectl create namespace fdr-test
namespace/fdr-test created

[root@k8s-master1 test]# helm install fdr-redis bitnami/redis -n fdr-test \
                         --set global.redis.password='ab123456' \
                         --set global.storageClass='managed-nfs-storage' \
                         --set master.persistence.size=1Gi \
                         --set replica.persistence.size=1Gi
NAME: fdr-redis
LAST DEPLOYED: Wed Dec 27 15:41:09 2023
NAMESPACE: fdr-test
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: redis
CHART VERSION: 18.6.1
APP VERSION: 7.2.3

** Please be patient while the chart is being deployed **

Redis® can be accessed on the following DNS names from within your cluster:

    fdr-redis-master.fdr-test.svc.cluster.local for read/write operations (port 6379)
    fdr-redis-replicas.fdr-test.svc.cluster.local for read-only operations (port 6379)



To get your password run:

    export REDIS_PASSWORD=$(kubectl get secret --namespace fdr-test fdr-redis -o jsonpath="{.data.redis-password}" | base64 -d)

To connect to your Redis® server:

1. Run a Redis® pod that you can use as a client:

   kubectl run --namespace fdr-test redis-client --restart='Never'  --env REDIS_PASSWORD=$REDIS_PASSWORD  --image docker.io/bitnami/redis:7.2.3-debian-11-r2 --command -- sleep infinity

   Use the following command to attach to the pod:

   kubectl exec --tty -i redis-client \
   --namespace fdr-test -- bash

2. Connect using the Redis® CLI:
   REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h fdr-redis-master
   REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h fdr-redis-replicas

To connect to your database from outside the cluster execute the following commands:

    kubectl port-forward --namespace fdr-test svc/fdr-redis-master 6379:6379 &
    REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h 127.0.0.1 -p 6379
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@k8s-master1 templates]# kubectl get all -n fdr-test
NAME                       READY   STATUS    RESTARTS   AGE
pod/fdr-redis-master-0     1/1     Running   0          3m20s
pod/fdr-redis-replicas-0   1/1     Running   0          3m20s
pod/fdr-redis-replicas-1   1/1     Running   0          2m42s
pod/fdr-redis-replicas-2   1/1     Running   0          94s

NAME                         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/fdr-redis-headless   ClusterIP   None             <none>        6379/TCP   3m20s
service/fdr-redis-master     ClusterIP   10.110.186.154   <none>        6379/TCP   3m20s
service/fdr-redis-replicas   ClusterIP   10.108.230.91    <none>        6379/TCP   3m20s

NAME                                  READY   AGE
statefulset.apps/fdr-redis-master     1/1     3m20s
statefulset.apps/fdr-redis-replicas   3/3     3m20s


[root@k8s-master1 templates]# kubectl get pvc -n fdr-test
NAME                              STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS          AGE
redis-data-fdr-redis-master-0     Bound    pvc-c75c25f0-18a6-44c5-b8e0-0cfd791b5f59   1Gi        RWO            managed-nfs-storage   4m4s
redis-data-fdr-redis-replicas-0   Bound    pvc-39caf5a7-c930-4958-b037-9f75c340b063   1Gi        RWO            managed-nfs-storage   4m4s
redis-data-fdr-redis-replicas-1   Bound    pvc-d689551e-1f9f-4c42-a1e5-55ea9b42302d   1Gi        RWO            managed-nfs-storage   3m26s
redis-data-fdr-redis-replicas-2   Bound    pvc-ed2edf54-9158-4c50-9d98-9e62347e8ae5   1Gi        RWO            managed-nfs-storage   2m18s

[root@k8s-master1 templates]# kubectl get pv -n fdr-test
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                                      STORAGECLASS          REASON   AGE
pvc-39caf5a7-c930-4958-b037-9f75c340b063   1Gi        RWO            Delete           Bound    fdr-test/redis-data-fdr-redis-replicas-0   managed-nfs-storage            4m7s
pvc-c75c25f0-18a6-44c5-b8e0-0cfd791b5f59   1Gi        RWO            Delete           Bound    fdr-test/redis-data-fdr-redis-master-0     managed-nfs-storage            4m7s
pvc-d689551e-1f9f-4c42-a1e5-55ea9b42302d   1Gi        RWO            Delete           Bound    fdr-test/redis-data-fdr-redis-replicas-1   managed-nfs-storage            3m29s
pvc-ed2edf54-9158-4c50-9d98-9e62347e8ae5   1Gi        RWO            Delete           Bound    fdr-test/redis-data-fdr-redis-replicas-2   managed-nfs-storage            2m21s

helm status

1
[root@k8s-master1 ~]# helm status fdr-redis -n fdr-test

helm upgrade

1
2
3
4
5
[root@k8s-master1 test]# helm upgrade fdr-redis bitnami/redis -n fdr-test \
                         --set global.redis.password='AB123456' \
                         --set global.storageClass='managed-nfs-storage' \
                         --set master.persistence.size=1Gi \
                         --set replica.persistence.size=1Gi

helm rollback

1
2
3
4
5
6
7
[root@k8s-master1 ~]# helm history fdr-redis -n fdr-test
REVISION	UPDATED                 	STATUS    	CHART       	APP VERSION	DESCRIPTION     
1       	Wed Dec 27 15:41:09 2023	superseded	redis-18.6.1	7.2.3      	Install complete
2       	Wed Dec 27 16:45:32 2023	deployed  	redis-18.6.1	7.2.3      	Upgrade complete

[root@k8s-master1 ~]# helm rollback fdr-redis 1 -n fdr-test
Rollback was a success! Happy Helming!

helm uninstall

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[root@k8s-master1 ~]# helm uninstall fdr-redis -n fdr-test
release "fdr-redis" uninstalled

[root@k8s-master1 ~]# kubectl get all -n fdr-test
No resources found in fdr-test namespace.

[root@k8s-master1 ~]# kubectl get pvc -n fdr-test
NAME                              STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS          AGE
redis-data-fdr-redis-master-0     Bound    pvc-c75c25f0-18a6-44c5-b8e0-0cfd791b5f59   1Gi        RWO            managed-nfs-storage   67m
redis-data-fdr-redis-replicas-0   Bound    pvc-39caf5a7-c930-4958-b037-9f75c340b063   1Gi        RWO            managed-nfs-storage   67m
redis-data-fdr-redis-replicas-1   Bound    pvc-d689551e-1f9f-4c42-a1e5-55ea9b42302d   1Gi        RWO            managed-nfs-storage   66m
redis-data-fdr-redis-replicas-2   Bound    pvc-ed2edf54-9158-4c50-9d98-9e62347e8ae5   1Gi        RWO            managed-nfs-storage   65m
[root@k8s-master1 ~]# kubectl get pv -n fdr-test
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                                      STORAGECLASS          REASON   AGE
pvc-39caf5a7-c930-4958-b037-9f75c340b063   1Gi        RWO            Delete           Bound    fdr-test/redis-data-fdr-redis-replicas-0   managed-nfs-storage            67m
pvc-c75c25f0-18a6-44c5-b8e0-0cfd791b5f59   1Gi        RWO            Delete           Bound    fdr-test/redis-data-fdr-redis-master-0     managed-nfs-storage            67m
pvc-d689551e-1f9f-4c42-a1e5-55ea9b42302d   1Gi        RWO            Delete           Bound    fdr-test/redis-data-fdr-redis-replicas-1   managed-nfs-storage            66m
pvc-ed2edf54-9158-4c50-9d98-9e62347e8ae5   1Gi        RWO            Delete           Bound    fdr-test/redis-data-fdr-redis-replicas-2   managed-nfs-storage            65m

[root@k8s-master1 ~]# kubectl delete pvc redis-data-fdr-redis-master-0 redis-data-fdr-redis-replicas-0 redis-data-fdr-redis-replicas-1 redis-data-fdr-redis-replicas-2  -n fdr-test
persistentvolumeclaim "redis-data-fdr-redis-master-0" deleted
persistentvolumeclaim "redis-data-fdr-redis-replicas-0" deleted
persistentvolumeclaim "redis-data-fdr-redis-replicas-1" deleted
persistentvolumeclaim "redis-data-fdr-redis-replicas-2" deleted

[root@k8s-master1 ~]# kubectl get pvc -n fdr-test
No resources found in fdr-test namespace.
[root@k8s-master1 ~]# kubectl get pv -n fdr-test
No resources found

[root@k8s-master1 ~]# kubectl delete namespace fdr-test
namespace "fdr-test" deleted