On this page
๐ญ 11. Helm ์ฐจํธ
1. Helm ๊ตฌ์ฑ ๋ฐ ์ฌ์ฉ
- Helm ๋ค์ด๋ก๋ ๋ฐ ์ค์น
์๋์ฐ ์ค์น
- Chocolatey ์ค์น
PowerShell ์ ์ด์ด์ ์๋ ๋ช ๋ น์ ์ํ ํฉ๋๋ค. ์ด๋ฏธ google cloud sdk ๋ฅผ ์ค์น ํ๋ฉด์ ์ค์น ๋์์์ ์์ต๋๋ค.
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
- Helm ์ค์น
choco install kubernetes-helm
Mac / LINUX ์ค์น
- ์๋ ์ค์น ๋ฐฉ๋ฒ
# helm ๋ค์ด๋ก๋
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
# ์คํ๊ถํ ๋ณ๊ฒฝ
chmod 700 get_helm.sh
# helm ์ค์น
./get_helm.sh
# ๋ฒ์ ํ์ธ
helm version
# Helm Repository ์ถ๊ฐ
helm repo add stable https://charts.helm.sh/stable
# Repository ์
๋ฐ์ดํธ
helm repo update
- Brew ์ค์น
brew install helm
2. Mysql Helm ์ฐจํธ ๋ค์ด๋ก๋ ๋ฐ ์ค์น
- mysql helm ๊ฒ์
helm search repo stable/mysql
NAME CHART VERSION APP VERSION DESCRIPTION
stable/mysql 1.6.3 5.7.28 Fast, reliable, scalable, and easy to use open-...
stable/mysqldump 2.6.0 2.4.1 A Helm chart to help backup MySQL databases usi...
- ํผํค์ง ๋ฉํ ์ ๋ณด ๋ณด๊ธฐ
helm show chart stable/mysql
apiVersion: v1
appVersion: 5.7.28
description: Fast, reliable, scalable, and easy to use open-source relational database
system.
home: https://www.mysql.com/
icon: https://www.mysql.com/common/logos/logo-mysql-170x115.png
keywords:
- mysql
- database
- sql
maintainers:
- email: o.with@sportradar.com
name: olemarkus
- email: viglesias@google.com
name: viglesiasce
name: mysql
sources:
- https://github.com/kubernetes/charts
- https://github.com/docker-library/mysql
version: 1.6.3
- mysql helm ์ฐจํธ ์ค์น ๋ฐ Deployment
helm install mysql stable/mysql
AME: mysql-1588321002
LAST DEPLOYED: Fri May 1 08:16:55 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
mysql-1588321002.default.svc.cluster.local
To get your root password run:
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)
i99OpY3CRp
To connect to your database:
1. Run an Ubuntu pod that you can use as a client:
kubectl run -i --tty ubuntu --image=ubuntu:16.04 --restart=Never -- bash -il
2. Install the mysql client:
$ apt-get update && apt-get install mysql-client -y
3. Connect using the mysql cli, then provide your password:
$ mysql -h mysql -p
To connect to your database directly from outside the K8s cluster:
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
# Execute the following command to route the connection:
kubectl port-forward svc/mysql-1588321002 3306
mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
helm ls
NAME NAMESPACE REVISION UPDATED STATUS C
HART APP VERSION
mysql-1588321701 default 1 2020-05-01 17:28:25.322363879 +0900 +09 deployed m
ysql-1.6.3 5.7.28
- helm ์ฐจํธ uninstall
heml list
NAME NAMESPACE REVISION UPDATED STATUS C
HART APP VERSION
mysql-1588321701 default 1 2020-05-01 17:28:25.322363879 +0900 +09 deployed m
ysql-1.6.3 5.7.28
helm uninstall mysql-1588321701
release "mysql-1588321701" uninstalled
3. Helm ์ฐจํธ ๋ง๋ค๊ธฐ
- Helm ์ฐจํธ ์์ฑ
helm create nginxstd
- Template ํ์ผ ์์
- Charts.yaml ํ์ผ ์์
apiVersion: v2
name: nginx-std
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: "1.16.0"
- Template/deployment.yaml ํ์ผ ์์ฑ
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.container.name }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app: {{ .Values.container.name }}
template:
metadata:
labels:
app: {{ .Values.container.name }}
environment: {{ .Values.environment }}
spec:
containers:
- name: {{ .Values.container.name }}
image: {{ .Values.container.image }}:{{ .Values.container.tag }}
ports:
- containerPort: {{ .Values.container.port }}
env:
- name: environment
value: {{ .Values.environment }}
- template/service.yaml ํ์ผ ์์ฑ
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.container.name }}-service
labels:
app: {{ .Values.container.name }}
spec:
ports:
- port: 80
protocol: TCP
targetPort: {{ .Values.container.port }}
selector:
app: {{ .Values.container.name }}
type: LoadBalancer
- values.yaml ํ์ผ ์์ฑ
environment: development
container:
name: nginx
port: 80
image: nginx
tag: latest
replicas: 2
- ํ ์คํธ ํ๊ธฐ
- K8s ์ค๋ธ์ ํธ ์์ฑ
helm install nginxstd ./nginxstd
- ์ญ์
# ํ์ธ
kubectl get all
helm list
# ์ญ์
helm uninstall nginxstd
4. ํจํค์ง ๋ฐ ๋ฆฌํฌ์งํ ๋ฆฌ ์์ฑ
- ํจํค์ง ์์ฑ
helm package ./nginxstd
mkdir prod
mv ./nginx-std-0.1.0.tgz ./prod/
- helm ๋ฆฌํฌ์งํ ๋ฆฌ ํ์ผ ์์ฑ
# ๋ฆฌํฌ์งํ ๋ฆฌ ํ์ผ ์์ฑ (index.yaml)
heml repo index ./prod
# ํ์ผ ์์ฑ ํ์ธ
cat ./prod/index.yaml
5 Helm ํจํค์ง ๋ฐ Repository ๊ตฌ์ฑํ๊ธฐ
- Github.com Repository ์์ฑ
- repository ์์ฑ
- github page ์ค์
- Git repository ์์ฑ ๋ฐ ๋๊ธฐํ
cd prod
git init
git add .
git brancb -m main
git commit -a -m "initial commit"
git remote add origin https://github.com/dangtong76/helm-prod.git
git push origin main
- Helm ๋ฆฌํฌ์งํ ๋ฆฌ ๊ตฌ์ฑ ๋ฐ ์ถ๊ฐ
- Git page ๋ก ์๋น์ค ๋๋ Git ๋ฆฌํฌ์งํ ๋ฆฌ๋ฅผ Helm ๋ฆฌํฌ์งํ ๋ฆฌ์ ์ถ๊ฐ
helm repo add helm-prod https://dangtong76.github.io/helm-prod
- ์ถ๊ฐํ์ธ
helm repo list
helm search repo nginx
- Helm ๋ฆฌํฌ์งํ ๋ฆฌ์ redis ์ถ๊ฐ
- redis ์์ ๋ฒ์ ์ฐจํธ๋ฅผ ๋ก์ปฌ prod ๋๋ ํ ๋ฆฌ์ ๋ค์ด๋ก๋
helm search repo redis
helm fetch stable/redis -d ./prod
- index.yaml ๊ฐฑ์ฑ
helm repo index ./prod
- git ์ ๋ฐ์ดํธ
git status
git add .
git commit -a -m "add redis"
git push origin master
- helm update ์ํ
helm repo update
helm search repo redis
์ ๋ฐ์ดํธ ์์ด “helm search repo redis” ๋ฅผ ๊ฒ์ํ๋ฉด ๊ฒ์์ด ๋์ง ์์ต๋๋ค.
6 Helm ์ฐจํธ ์ ๊ทธ๋ ์ด๋
- Repository ๋ฅผ ํตํ Helm ์ธ์คํจ
helm list
helm install nginxstd helm-prod/nginx-std
# ๋๋
helm install helm-prod/nginx-std --generate-name
#ํ์ธ
helm status nginxstd
kubectl get all
- helm ๋ฉ๋ํ์คํธ๋ฅผ ํตํ ์ฐจํธ ๋ณ๊ฒฝ ๋ฐ ์ ๋ฐ์ดํธ
- stage-values.yaml ํ์ผ ์์ฑ
environment: development
replicas: 4
- helm upgrade ๋ก ์ฐจํธ ๋ณ๊ฒฝ ์ ์ฉ
helm upgrade -f ./nginxstd/stage-values.yaml nginxstd helm-prod/nginx-std
- helm history ๋ก ํ์ธ
helm history
- RollBack ์ํ
helm rollback nginxstd 1
- Rollback ํ์ธ
helm history nginxstd
helm helm status nginxstd
kubectl get po
- Helm CLI ์ต์ ์ ํตํ ์ ๊ทธ๋ ์ด๋
- ํ์ฌ ์ฐจํธ์ value ๋ฅผ ํ์ธ
helm show values helm-prod/nginx-std
environment: development
container:
name: nginx
port: 80
image: nginx:1.7.9
tag: hello
replicas: 2
- CLI ์ต์ ์ ํตํ ์ ๊ทธ๋ ์ด๋
helm upgrade --set replicas=4 --set environment=dev nginxstd helm-prod/nginx-std
- ํ์ธ
helm history
helm status nginxstd
kubectl get po
7 ์ญ์
helm uninstall nginxstd
[์ฐ์ต๋ฌธ์ ] 11-1. Helm ์ฐจํธ ์ค์น ์ค์ต
๋ฌธ์ :
- Helm ์ ์ฅ์์์ stable/mysql ์ฐจํธ๋ฅผ ๊ฒ์ํด๋ณด์ธ์.
- Helm์ ์ด์ฉํด
mydb๋ผ๋ ์ด๋ฆ์ผ๋ก MySQL์ ์ค์นํ๊ณ , root ๋น๋ฐ๋ฒํธ๋ฅผrootpw1234๋ก ์ง์ ํ์ธ์. - ์ค์น๊ฐ ์๋ฃ๋ ํ, kubectl ๋ช ๋ น์ด๋ก MySQL์ root ๋น๋ฐ๋ฒํธ๋ฅผ ํ์ธํด๋ณด์ธ์.
ํํธ:
helm search repo๋ช ๋ น์ด๋ก ์ฐจํธ๋ฅผ ๊ฒ์ํ ์ ์์ต๋๋ค.--set์ต์ ์ผ๋ก ์ฐจํธ์ ๊ฐ์ ์ค๋ฒ๋ผ์ด๋ํ ์ ์์ต๋๋ค.- ๋น๋ฐ๋ฒํธ๋ Secret์ base64๋ก ์ ์ฅ๋ฉ๋๋ค.
[์ฐ์ต๋ฌธ์ ] 11-2. Helm ์ฐจํธ ๊ฐ ์ค๋ฒ๋ผ์ด๋ ์ค์ต
๋ฌธ์ :
- Helm์ ์ด์ฉํด
mydb2๋ผ๋ ์ด๋ฆ์ผ๋ก MySQL์ ์ค์นํ์ธ์. - ๋ค์ ๊ฐ์ ์ง์ ์ง์ ํ์ธ์:
- MySQL ์ฌ์ฉ์๋ช
:
user1 - MySQL ์ฌ์ฉ์ ๋น๋ฐ๋ฒํธ:
pw5678 - ์์ฑํ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ด๋ฆ:
testdb - root ๋น๋ฐ๋ฒํธ:
rootpw1234
- MySQL ์ฌ์ฉ์๋ช
:
ํํธ:
- ์ฌ๋ฌ ๊ฐ์ ์ค๋ฒ๋ผ์ด๋ํ ๋๋
--set์ต์ ์ ์ฌ๋ฌ ๋ฒ ์ฌ์ฉํ๊ฑฐ๋, ์ผํ(,)๋ก ๊ตฌ๋ถํ ์ ์์ต๋๋ค.
[์ฐ์ต๋ฌธ์ ] 11-3. Helm ์ฐจํธ ์ง์ ๋ง๋ค๊ธฐ
๋ฌธ์ :
nginx-std๋ผ๋ ์ด๋ฆ์ Helm ์ฐจํธ๋ฅผ ์์ฑํ์ธ์.- ์์ฑ๋ ์ฐจํธ์
values.yamlํ์ผ์์ replica ์๋ฅผ 3, ํ๊ฒฝ(environment)์ prod๋ก ๋ณ๊ฒฝํ์ธ์. - ์์ ํ ์ฐจํธ๋ฅผ
mynginx๋ผ๋ ์ด๋ฆ์ผ๋ก ์ค์นํ์ธ์.
ํํธ:
helm create๋ช ๋ น์ด๋ก ์ฐจํธ ๋ผ๋๋ฅผ ๋ง๋ค ์ ์์ต๋๋ค.values.yamlํ์ผ์์ ๊ธฐ๋ณธ๊ฐ์ ์ํ๋ ๊ฐ์ผ๋ก ๋ฐ๊ฟ์ฃผ์ธ์.- ์ค์น ์ ์ฐจํธ ๋๋ ํ ๋ฆฌ ๊ฒฝ๋ก๋ฅผ ์ง์ ํด์ผ ํฉ๋๋ค.