helm은 "투구"의 의미가 아니라 항해에 사용되는 "키" 또는 "조타"를 의미하며, chart는 "해도", tiller는 "키의 손잡이"라는 의미임
Helm이란 Kubernetes(K8s) 애플리케이션 관리 도구(패키지 매니저)임
Helm chart란 helm을 이용해서 설치 가능한 패키지임
Ubuntu Linux에 비유하자면, helm은 apt 같은 패키지 매니저로서 기능하고 chart는 mysql-server 패키지에 해당함
kubectl을 이용해서 직접 애플리케이션 이미지를 지정하여 컨테이너로 설치하고 서비스로 구성할 수 있지만, helm을 이용하면 좀 더 편리하게 설치할 수 있음
Helm은 버전에 따른 구조나 기능의 차이가 큰 편이어서, 아래 내용은 3.8.0 버전을 기준으로 하고 있음을 밝힘
macOS에서는 brew를 이용해서 설치함
brew install helm
Ubuntu Linux에서는 apt를 이용해서 설치하며, 설치 전에 패키지 저장소를 추가해줘야 함
curl https://baltocdn.com/helm/signing.asc | sudo apt-key add -
sudo apt-get install apt-transport-https --yes
echo "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
sudo apt-get update
sudo apt-get install helm
helm repo list
아직 어떤 저장소도 추가하지 않았기 때문에 어떤 저장소도 없음
추가되어 있는 저장소에 대한 검색이 가능함
helm search repo kafka
hub에 등록된 패키지를 검색할 수 있음. Kafka를 검색해 봄
helm search hub kafka
URL CHART VERSION APP VERSION DESCRIPTION
https://artifacthub.io/packages/helm/bitnami-ak... 15.3.4 3.1.0 Apache Kafka is a distributed streaming platfor...
https://artifacthub.io/packages/helm/bitnami/kafka 15.3.4 3.1.0 Apache Kafka is a distributed streaming platfor...
https://artifacthub.io/packages/helm/riftbit/kafka 14.2.0 2.8.1 Apache Kafka is a distributed streaming platform.
https://artifacthub.io/packages/helm/openstack-... 0.1.1 v2.12-2.3.0 OpenStack-Helm Kafka
https://artifacthub.io/packages/helm/banzaiclou... 0.3.3 2.0.0 Kafka cluster for kubernetes with native etcd s...
Artfiact hub은 bitnami와 달리 공식 hub이므로 repo로 등록하는 게 아니고 hub으로 기본 제공된다.
helm search hub kafka
등록 과정이 불필요하다.
chart의 endpoint를 확인하기 어려우니 최대 컬럼 폭을 지정해주자.
helm search hub kafka --max-col-width 200
웹페이지로도 제공하고 있다. CLI 대신에 여기서 검색하는 게 더 편리하다.
https://artifacthub.io/
hub은 검색 엔진 역할을 해줄 뿐, 실제로 chart를 설치하려면 해당 chart를 제공하는 repo를 우선 등록해야 사용할 수 있다. 아래 repo를 등록하는 절차를 살펴보자.
맨 윗줄에 나온 것처럼 bitnami가 chart 저장소로 유명함. 이걸 저장소로 추가해주자.
helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" 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 "crossplane-stable" chart repository
...Successfully got an update from the "bitnami" chart repository
Update Complete. ⎈Happy Helming!⎈
이제 bitnami 저장소에서 chart를 검색할 수 있다.
helm search repo
helm search repo redis
bitnami 저장소에는 100여 개의 chart가 등록되어 있음. apache, nginx, tomcat, consul, elasticsearch, kibana, logstash, node-exporter, grafana, thanos, influxdb, haproxy, kafka, rabbitmq, logstash, mysql, mariadb, postgresql, mongodb, redis, spark, tensorflow, pytorch, zookeeper, wordpress, dockuwiki, ...
mq라는 이름의 namespace로 "kafka" chart를 설치함
helm install kafka bitnami/kafka --create-namespace --namespace mq
NAME: kafka
LAST DEPLOYED: Thu Mar 3 11:42:13 2022
NAMESPACE: mq
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: kafka
CHART VERSION: 15.3.4
APP VERSION: 3.1.0
** Please be patient while the chart is being deployed **
Kafka can be accessed by consumers via port 9092 on the following DNS name from within your cluster:
kafka.mq.svc.cluster.local
Each Kafka broker can be accessed by producers via port 9092 on the following DNS name(s) from within your cluster:
kafka-0.kafka-headless.mq.svc.cluster.local:9092
To create a pod that you can use as a Kafka client run the following commands:
kubectl run kafka-client --restart='Never' --image docker.io/bitnami/kafka:3.1.0-debian-10-r31 --namespace mq --command -- sleep infinity
kubectl exec --tty -i kafka-client --namespace mq -- bash
PRODUCER:
kafka-console-producer.sh \
--broker-list kafka-0.kafka-headless.mq.svc.cluster.local:9092 \
--topic test
CONSUMER:
kafka-console-consumer.sh \
--bootstrap-server kafka.mq.svc.cluster.local:9092 \
--topic test \
--from-beginning
설치가 되면 접근가능한 DNS 이름과 포트 번호를 알려주고, 클라이언트용 pod를 실행하는 방법을 안내해 줌
redis를 설치해보면 약간 다른 결과가 나오지만, 대체적인 내용은 비슷함
❯ helm install redis bitnami/redis --create-namespace --namespace cache
NAME: redis
LAST DEPLOYED: Thu Mar 3 11:44:33 2022
NAMESPACE: cache
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: redis
CHART VERSION: 16.4.5
APP VERSION: 6.2.6
** Please be patient while the chart is being deployed **
Redis™ can be accessed on the following DNS names from within your cluster:
redis-master.cache.svc.cluster.local for read/write operations (port 6379)
redis-replicas.cache.svc.cluster.local for read-only operations (port 6379)
To get your password run:
export REDIS_PASSWORD=$(kubectl get secret --namespace cache redis -o jsonpath="{.data.redis-password}" | base64 --decode)
To connect to your Redis™ server:
1. Run a Redis™ pod that you can use as a client:
kubectl run --namespace cache redis-client --restart='Never' --env REDIS_PASSWORD=$REDIS_PASSWORD --image docker.io/bitnami/redis:6.2.6-debian-10-r142 --command -- sleep infinity
Use the following command to attach to the pod:
kubectl exec --tty -i redis-client --namespace cache -- bash
2. Connect using the Redis™ CLI:
REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis-master
REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis-replicas
To connect to your database from outside the cluster execute the following commands:
kubectl port-forward --namespace cache svc/redis-master : &
REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h 127.0.0.1 -p
install 명령 대신 upgrade 명령도 사용 가능함
helm upgrade kafka bitnami/kafka --create-namespace --namespace mq
helm list -n mq
helm list -A
kubectl get all -n mq
9092번 포트에 kafka broker 서비스가 바인딩되어 있음
zookeeper 서비스도 설치되어 있음
NAME READY STATUS RESTARTS AGE
pod/kafka-0 1/1 Running 0 148m
pod/kafka-client 1/1 Running 0 9m16s
pod/kafka-zookeeper-0 1/1 Running 0 148m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kafka ClusterIP 10.103.136.23 <none> 9092/TCP 148m
service/kafka-headless ClusterIP None <none> 9092/TCP,9093/TCP 148m
service/kafka-zookeeper ClusterIP 10.96.166.2 <none> 2181/TCP,2888/TCP,3888/TCP 148m
service/kafka-zookeeper-headless ClusterIP None <none> 2181/TCP,2888/TCP,3888/TCP 148m
NAME READY AGE
statefulset.apps/kafka 1/1 148m
statefulset.apps/kafka-zookeeper 1/1 148m
helm으로 chart를 설치하면 일반적으로 서비스는 자동으로 설치되어 기동하는데, 클라이언트는 별도로 실행해줘야 함. 클라이언트도 K8s 클러스터 내에서 pod으로 실행하고 싶다면 위 설치 명령의 가이드대로 실행하면 됨
kubectl run kafka-client --restart='Never' --image docker.io/bitnami/kafka:3.1.0-debian-10-r31 --namespace mq --command -- sleep infinity
pod/kafka-client created
무한 대기하는 kafka-client pod를 실행시키고, bash를 실행해서 접속해보면 kafka client CLI 명령을 사용할 수 있게 됨
kubectl exec --tty -i kafka-client --namespace mq -- bash
I have no name!@kafka-client:/$
producer쪽 client를 실행하려면, 다음과 같이 Kafka 클러스터의 broker 서버의 endpoint와 토픽명을 지정해서 실행할 수 있음
kafka-console-producer.sh --broker-list kafka-0.kafka-headless.mq.svc.cluster.local:9092 --topic test
consumer쪽 client를 실행하려면, 비슷하게 broker 서버의 endpoint와 토픽명을 지정해서 실행할 수 있음
kafka-console-consumer.sh --bootstrap-server kafka.mq.svc.cluster.local:9092 --topic test --from-beginning
helm uninstall kafka -n mq
release "kafka" uninstalled