본문 바로가기

Helm (헬름)/Helm

Helm 을 활용한 nginx 배포하기

1. helm 설치

2021.10.24 - [Kubernetes & EKS/Helm] - Helm이란?

 

Helm이란?

Helm 차트를 활용한 애플리케이션 패키지 배포 쿠버네티스 애플리케이션 관리를 지원하는 도구 Helm 이란? Helm 은 쿠버네티스 package managing tool 이다. node.js 의 npm 과 비슷한 형태로 쿠버네티스

may9noy.tistory.com

EKS 워크샵 URL : https://awskrug.github.io/eks-workshop/helm_root/helm_nginx/searchchart/

 

EKSworkshop.com

In this workshop, we will explore multiple ways to configure VPC, ALB, and EC2 Kubernetes workers, and Amazon Elastic Kubernetes Service.

www.eksworkshop.com

tiller를 위한 계정 및 권한을 설정

cat <<EoF > ./rbac.yaml
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: tiller
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: tiller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: tiller
    namespace: kube-system
EoF

2. Helm을 활용하여 nginx 배포

Helm 레파지토리 업데이트, Helm 레파지토리는 주기적으로 업데이트 되는 저장소 이므로 자주 업데이트하여 리스트를 확인해야 한다.

helm repo update

실행하면 다음과 같은 화면이 나온다.

helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "grafana" chart repository
...Successfully got an update from the "prometheus-community" chart repository
Update Complete. ⎈Happy Helming!⎈

차트 레파지토리 검색

차트를 새로운 리드트로 업데이트 한 후 사용할 레파지토리를 검색해보자.

helm search

helm search는 모든 레파지토리 리스트를 검색한다.

하지만 검색이 되지 않고 아래와 같은 안내 문구가 나온다.

아마도 검색을 하기 위해서는 중간에 repo나 hub 등을 추가해서 검색을 해야할거 같다.

Search provides the ability to search for Helm charts in the various places
they can be stored including the Artifact Hub and repositories you have added.
Use search subcommands to search different locations for charts.

Usage:
  helm search [command]

Available Commands:
  hub         search for charts in the Artifact Hub or your own hub instance
  repo        search repositories for a keyword in charts

Flags:
  -h, --help   help for search

Global Flags:
      --debug                       enable verbose output
      --kube-apiserver string       the address and the port for the Kubernetes API server
      --kube-as-group stringArray   group to impersonate for the operation, this flag can be repeated to specify multiple groups.
      --kube-as-user string         username to impersonate for the operation
      --kube-ca-file string         the certificate authority file for the Kubernetes API server connection
      --kube-context string         name of the kubeconfig context to use
      --kube-token string           bearer token used for authentication
      --kubeconfig string           path to the kubeconfig file
  -n, --namespace string            namespace scope for this request
      --registry-config string      path to the registry config file (default "/home/ubuntu/.config/helm/registry/config.json")
      --repository-cache string     path to the file containing cached repository indexes (default "/home/ubuntu/.cache/helm/repository")
      --repository-config string    path to the file containing repository names and URLs (default "/home/ubuntu/.config/helm/repositories.yaml")

Use "helm search [command] --help" for more information about a command.

다시 nginx를 helm에서 검색해보자.

helm search repo nginx

검색을 해보면 아래와 같이 여러가지 버전의 nginx를 찾을 수 있다.

helm search repo nginx
NAME                                    CHART VERSION   APP VERSION     DESCRIPTION
bitnami/nginx                           9.9.7           1.21.6          NGINX Open Source is a web server that can be a...
bitnami/nginx-ingress-controller        9.1.14          1.1.2           NGINX Ingress Controller is an Ingress controll...
bitnami/nginx-intel                     0.1.9           0.4.7           NGINX Open Source for Intel is a lightweight se...
stable/nginx-ingress                    1.41.3          v0.34.1         DEPRECATED! An nginx Ingress controller that us...
stable/nginx-ldapauth-proxy             0.1.6           1.13.5          DEPRECATED - nginx proxy with ldapauth
stable/nginx-lego                       0.3.1                           Chart for nginx-ingress-controller and kube-lego
bitnami/kong                            5.0.2           2.7.0           Kong is a scalable, open source API layer (aka ...
stable/gcloud-endpoints                 0.1.2           1               DEPRECATED Develop, deploy, protect and monitor...

3. bitnami의 nginx를 설치해보자.

검색가능한 차트 목록에 bitnami의 레포지토리를 추가한다.

helm repo add bitnami https://charts.bitnami.com/bitnami

그리고 bitnami의 repository를 검색해본다.

helm search repo bitnami

다수의 리스트 목록을 확인 할 수 있다.

NAME                                            CHART VERSION   APP VERSION     DESCRIPTION                                  
bitnami/bitnami-common                          0.0.9           0.0.9           DEPRECATED Chart with custom templates used in ...
bitnami/airflow                                 12.0.16         2.2.4           Apache Airflow is a tool to express and execute...
bitnami/apache                                  9.0.13          2.4.53          Apache HTTP Server is an open-source HTTP serve...
bitnami/argo-cd                                 3.1.7           2.3.2           Argo CD is a continuous delivery tool for Kuber...
bitnami/argo-workflows                          1.1.2           3.3.1           Argo Workflows is meant to orchestrate Kubernet...
bitnami/aspnet-core                             3.1.13          6.0.3           ASP.NET Core is an open-source framework for we...
bitnami/cassandra                               9.1.13          4.0.3           Apache Cassandra is an open source distributed ...
bitnami/cert-manager                            0.4.11          1.7.2           Cert Manager is a Kubernetes add-on to automate...
bitnami/common                                  1.13.0          1.13.0          A Library Helm Chart for grouping common logic ...
.
.
.

그렇다면 이제 설치할 bitnami/nginx를 검색해보자.

아래와 같이 nginx와 관련된 리스트를 확인 할 수 있다.

helm search repo bitnami/nginx
NAME                                    CHART VERSION   APP VERSION     DESCRIPTION
bitnami/nginx                           9.9.7           1.21.6          NGINX Open Source is a web server that can be a...
bitnami/nginx-ingress-controller        9.1.14          1.1.2           NGINX Ingress Controller is an Ingress controll...
bitnami/nginx-intel                     0.1.9           0.4.7           NGINX Open Source for Intel is a lightweight se...

bitnami/nginx 설치

helm install mywebserver bitnami/nginx

아래와 같이 생성된다.

helm install mywebserver bitnami/nginx
NAME: mywebserver
LAST DEPLOYED: Tue Mar 29 04:56:42 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: nginx
CHART VERSION: 9.9.7
APP VERSION: 1.21.6

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

NGINX can be accessed through the following DNS name from within your cluster:

    mywebserver-nginx.default.svc.cluster.local (port 80)

To access NGINX from outside the cluster, follow the steps below:

1. Get the NGINX URL by running these commands:

  NOTE: It may take a few minutes for the LoadBalancer IP to be available.
        Watch the status with: 'kubectl get svc --namespace default -w mywebserver-nginx'

    export SERVICE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].port}" services mywebserver-nginx)
    export SERVICE_IP=$(kubectl get svc --namespace default mywebserver-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
    echo "http://${SERVICE_IP}:${SERVICE_PORT}"

4. 배포한 bitnami/nginx 확인하기

배포한 pod의 세부정보 확인

kubectl describe deployment mywebserver-nginx

배포한 pod의 정상 실행여부 확인

kubectl get pod
NAME                                 READY   STATUS    RESTARTS   AGE
mywebserver-nginx-7c7c66dff7-f8dm2   1/1     Running   0          3m10s

배포한 pod의 전체 URL을 확인

kubectl get service mywebserver-nginx -o wide
NAME                TYPE           CLUSTER-IP      EXTERNAL-IP                                                                    PORT(S)        AGE     SELECTOR
mywebserver-nginx   LoadBalancer   172.20.169.30   a766c58c2df99418a95ab5b295de7909-1426809480.ap-northeast-2.elb.amazonaws.com   80:31958/TCP   4m21s   app.kubernetes.io/instance=mywebserver,app.kubernetes.io/name=nginx

EXTERNAL-IP의 주소로 접근하면 아래와 같은 nginx 기본 페이지를 확인 할 수 있다.

추가로, 아래의 명령어로도 EXTERNAL-IP가 확인 가능하다.

kubectl get svc
NAME                TYPE           CLUSTER-IP      EXTERNAL-IP                                                                    PORT(S)        AGE
kubernetes          ClusterIP      172.20.0.1      <none>                                                                         443/TCP        5d22h
mywebserver-nginx   LoadBalancer   172.20.169.30   a766c58c2df99418a95ab5b295de7909-1426809480.ap-northeast-2.elb.amazonaws.com   80:31958/TCP   10m

5. 위에서 작업한 내용 삭제하기

# pod 조회, heml으로 설치되어있는 pod 확인
kubectl get pod
NAME                                 READY   STATUS    RESTARTS   AGE
mywebserver-nginx-7c7c66dff7-f8dm2   1/1     Running   0          43m

# helm으로 설치한 리스트 목록 조회
helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
mywebserver     default         1               2022-03-29 04:56:42.875197188 +0000 UTC deployed        nginx-9.9.7     1.21.6

# 조회된 목록 삭제
helm delete mywebserver
release "mywebserver" uninstalled

# 다시 pod 조회, 삭제되고 존재하지 않음.
kubectl get pod
No resources found in default namespace.

# svc도 조회, 삭제하여 존재하지 않음
kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   172.20.0.1   <none>        443/TCP   5d23h

# 정상적으로 삭제 완료.

끝.