헬름(Helm)은 쿠버네티스의 패키지 관리자이다. 헬름은 오픈 소스 소프트웨어로 공개되어 있으며, 이미 많은 패키지(Chart)가 있다. 예를들어 레디스 클러스터나 워드프레스 환경 등의 소프트웨어를 하나의 명령어로 쿠버네티스 클러스터에 배포할 수 있다.

 

또한, 롤링 업데이트 등에도 지원하는 것들이 많아 쿠버네티스에서 최적화된 설정으로 사용할 수 있는 장점이 있다.

 

헬름은 클라이언트 측에서 처리하기 때문에 kubectl과 같은 인증 정보를 사용한다.

 

기본적으로 ~/.kube/config를 사용한다.

 

시스템이 대규모로 바뀔수록 비슷한 매니페스트를 대량으로 만들어야 하므로 재사용이나 일괄 변경 작업이 어려워진다. 그래서 필요한 것이 매니페스트 범용화라는 개념이다. 매니페스트를 범용화하고 관리하는 방법을 알아보자.

 

기본적인 헬름 설치 및 사용법을 살펴보자.

헬름 설치

$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
$ chmod 700 get_helm.sh
$ ./get_helm.sh

헬름 저장소 추가

# 저장소 추가
$ helm repo add stable https://charts.helm.sh/stable
"stable" has been added to your repositories

$ helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories

# 등록된 저장소 표시
$ helm repo list
NAME   	URL                               
stable 	https://charts.helm.sh/stable     
bitnami	https://charts.bitnami.com/bitnami

# 저장소 업데이트
$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "stable" chart repository
...Successfully got an update from the "bitnami" chart repository
Update Complete. ⎈Happy Helming!⎈

차트 검색

- 차트 버전 : 템플릿 내용이나 초기 설정값이 변경될 때 업데이트 됨

- 앱 버전 : 실제 애플리케이션 버전

- 아티팩트 허브 : https://artifacthub.io/

# 저장소에서 차트 검색
$ helm search repo wordpress
NAME             	CHART VERSION	APP VERSION	DESCRIPTION                                       
bitnami/wordpress	12.1.24      	5.8.1      	Web publishing platform for building blogs and ...
stable/wordpress 	9.0.3        	5.3.2      	DEPRECATED Web publishing platform for building...

# 헬름 허브에서 차트 검색
$ helm search hub wordpress
URL                                               	CHART VERSION 	APP VERSION        	DESCRIPTION                                       
https://artifacthub.io/packages/helm/kube-wordp...	0.1.0         	1.1                	this is my wordpress package                      
https://artifacthub.io/packages/helm/bitnami/wo...	12.1.24       	5.8.1              	Web publishing platform for building blogs and ...
https://artifacthub.io/packages/helm/groundhog2...	0.4.2         	5.8.1-apache       	A Helm chart for Wordpress on Kubernetes          
https://artifacthub.io/packages/helm/riftbit/wo...	12.1.16       	5.8.1              	Web publishing platform for building blogs and ...
https://artifacthub.io/packages/helm/bitnami-ak...	12.1.18       	5.8.1              	Web publishing platform for building blogs and ...
https://artifacthub.io/packages/helm/mcouliba/w...	0.1.0         	1.16.0             	A Helm chart for Kubernetes                       
https://artifacthub.io/packages/helm/homeenterp...	0.1.0         	5.8.0-php8.0-apache	Blog server                                       
https://artifacthub.io/packages/helm/securecode...	3.3.0         	4.0                	Insecure & Outdated Wordpress Instance: Never e...
https://artifacthub.io/packages/helm/wordpressm...	1.0.0         	                   	This is the Helm Chart that creates the Wordpre...
https://artifacthub.io/packages/helm/bitpoke/wo...	0.11.0-rc.2   	0.11.0-rc.2        	Bitpoke WordPress Operator Helm Chart             
https://artifacthub.io/packages/helm/presslabs/...	0.11.0-alpha.3	0.11.0-alpha.3     	Presslabs WordPress Operator Helm Chart           
https://artifacthub.io/packages/helm/presslabs/...	0.11.1        	v0.11.1            	A Helm chart for deploying a WordPress site on ...
https://artifacthub.io/packages/helm/phntom/bin...	0.0.3         	0.0.3              	www.binaryvision.co.il static wordpress           
https://artifacthub.io/packages/helm/gh-shessel...	1.0.34        	5.8.0              	Web publishing platform for building blogs and ...
https://artifacthub.io/packages/helm/sonu-wordp...	1.0.0         	2                  	This is my custom chart to deploy wordpress and...
https://artifacthub.io/packages/helm/uvaise-wor...	0.2.0         	1.1.0              	Wordpress for Kubernetes                          
https://artifacthub.io/packages/helm/wordpress/...	0.2.0         	1.1.0              	Wordpress for Kubernetes                          
https://artifacthub.io/packages/helm/wordpress-...	1.0.0         	2                  	This is my custom chart to deploy wordpress and...
https://artifacthub.io/packages/helm/securecode...	3.3.0         	v3.8.19            	A Helm chart for the WordPress security scanner...
https://artifacthub.io/packages/helm/viveksahu2...	1.0.0         	2                  	This is my custom chart to deploy wordpress and...
https://artifacthub.io/packages/helm/presslabs/...	0.11.0-rc.2   	v0.11.0-rc.2       	Open-Source WordPress Infrastructure on Kubernetes
https://artifacthub.io/packages/helm/presslabs/...	0.11.1        	v0.11.1            	Open-Source WordPress Infrastructure on Kubernetes
https://artifacthub.io/packages/helm/six/wordress 	0.2.0         	1.1.0              	Wordpress for Kubernetes                          
https://artifacthub.io/packages/helm/wordpressm...	0.1.0         	1.1                	                                                  
https://artifacthub.io/packages/helm/presslabs/...	0.11.3        	0.11.3             	Presslabs WordPress Operator Helm Chart

차트 설치

- 각 차트마다 설정가능한 values 들이 있고, 이를 커스터마이징 하는 것이 아주 중요하다.

- 헬름 클라이언트는 헬름 저장소에서 다운로드한 차트와 values의 조합을 릴리스로 관리하고 쿠버네티스의 시크릿으로 데이터를 저장한다. 따라서 별도의 데이터베이스가 필요하지 않다.

# 설정 가능한 파라미터 표시
$ helm show values bitnami/wordpress

# README
$ helm show readme bitnami/wordpress

# 설치 명령어에 파라미터를 지정하여 설치
$ helm install sample-wordpress bitnami/wordpress --version 10.9.1 \
--set wordpressUsername=sample-user \
--set wordpressPassword=sample-pass \
--set wordpressBlogName="sample blog" \
--set persistence.size=5Gi

# values 파일을 생성하여 설치
$ helm install sample-wordpress bitnami/wordpress --version 10.9.1 \
--values values.yaml

# 테스트
$ helm test sample-wordpress

 

다음으로 개인적으로 아주 유용하다고 생각되는 템플릿 기능이다. 매니페스트의 특정 부분을 수정할 때 템플릿에서 해당하는 변수만을 수정하면 작업이 끝나기 때문에 sed 등을 사용한 매니페스트 수정 작업에 비해 실수를 방지하기가 더 유리하다. 즉, 자주 사용되는 템플릿을 기반으로 커스텀 차트를 생성하고, 파라미터 혹은 values 파일을 통해 유용한 매니페스트를 생성해낼 수 있다.

템플릿으로 매니페스트 생성

# 설치 명령어에 파라미터를 지정하여 매니페스트 생성
$ helm template sample-wordpress bitnami/wordpress --version 10.9.1 \
--set wordpressUsername=sample-user \
--set wordpressPassword=sample-pass \
--set wordpressBlogName="sample blog" \
--set persistence.size=5Gi

# values 파일을 생성하여 매니페스트 생성
$ helm template sample-wordpress bitnami/wordpress --version 10.9.1 \
--values values.yaml

 

차트

헬름에서는 차트라는 단위로 시스템을 패키징하고 차트 내용은 쿠버네티스 매니페스트 템플릿과 변수가 메인이다. 한번 생성한 차트는 쿠버네티스 버전에 맞추어 매니페스트 유지 보수를 별도로 해야한다.

# 커서틈 차트 양식 생성
$ helm create sample-charts
$ cd sample-charts
$ tree
├── Chart.yaml
├── charts
├── templates
│   ├── NOTES.txt
│   ├── _helpers.tpl
│   ├── deployment.yaml
│   ├── hpa.yaml
│   ├── ingress.yaml
│   ├── service.yaml
│   ├── serviceaccount.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml

3 directories, 10 files

$ cd ..
$ helm install sample-helm sample-charts
NAME: sample-helm
LAST DEPLOYED: Tue Oct 26 23:06:13 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=sample-charts,app.kubernetes.io/instance=sample-helm" -o jsonpath="{.items[0].metadata.name}")
  export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT
파일명 용도
templates/*.yaml 설치하는 매니페스트 템플릿
templates/tests/*.yaml 설치한 차트가 정상적으로 동작하는지 테스트하는 매니페스트 템플릿
values.yaml 사용자가 나중에 덮어 쓸 수 있는 기본값 정의
templates/NOTES.txt helm install 시 출력되는 메시지
requirements.yaml 의존하는 차트와 해당 버전 기록
templates/_helpers.tpl 릴리스 이름으로 변수를 정의하는 등의 헬퍼 변수 정의
Chart.yaml 차트 메타데이터, 의존하는 다른 차트 명시

 

기타 명령

# 설치 후 릴리스 확인
$ helm list
NAME       	NAMESPACE	REVISION	UPDATED                             	STATUS  	CHART              	APP VERSION
sample-helm	default  	1       	2021-10-26 23:06:13.158183 +0900 KST	deployed	sample-charts-0.1.0	1.16.0    

# 릴리스 삭제
$ helm uninstall sample-wordpress

 

 


출처

- [Helm 설치] : https://helm.sh/docs/intro/install/

- [책] 쿠버네티스 완벽 가이드 마사야 아오야마 지음, 박상욱 옮김

'클라우드 컴퓨팅 > 쿠버네티스' 카테고리의 다른 글

Kubernetes TLS/PKI 살펴보기  (0) 2021.11.08
Kubernetes Monitoring with Prometheus  (0) 2021.10.27
Kubernetes 컨테이너 로그 집계  (0) 2021.10.26
Kubernetes Container Images  (0) 2021.10.24
AWS EKS 살펴보기  (0) 2021.10.23

쿠버네티스에서 기동하고 있는 컨테이너 로그를 중장기적으로 안정적으로 저장하려면 플루언트디(Fluentd)를 사용하여 클러스터 외부로 로그를 전송하는 것을 추천한다.

 

플루언트디를 쿠버네티스에 통합하여 사용할 때는 데몬셋을 사용하여 각 노드에 플루언트디 파드를 한 대씩 기동하는 방법으로 구현한다. 파드가 직접 플루언트디 파드에 로그를 전송하는 것처럼 보이지만, 실제로는 도커 컨테이너 표준 출력으로 출력된 로그가 노드의 /var/log/containers/ 아래에 저장되고, 그 로그 파일을 플루언트디 파드가 tail 플러그인을 사용하여 읽어들인다.

 

로그 저장소는 아래 그림과 같이 elasticsearch를 사용해도 되지만 그 밖에 AWS S3, GCP Cloud Logging 등을 사용해도 좋다.

출처 : https://blog.opstree.com/2019/12/17/collect-logs-with-fluentd-in-k8s-part-2/

 

쿠버네티스에서 로그를 집계할 경우에는 로그 중요도나 용량을 고려하면서 적절한 로그 전송 경로를 검토해보자. 경우에 따라서는 애그리게이션(aggregation)하는 역할을 중간에 넣어 집계 측 서버의 부하를 줄이는 것도 고려해보자.

 

RBAC

- ServiceAccount

apiVersion: v1
kind: ServiceAccount
metadata:
  name: fluentd
  namespace: kube-system

- ClusterRole

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: fluentd
rules:
- apiGroups:
  - ""
  resources:
  - pods
  - namespaces
  verbs:
  - get
  - list
  - watch

- ClusterRoleBinding

kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: fluentd
roleRef:
  kind: ClusterRole
  name: fluentd
  apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
  name: fluentd
  namespace: kube-system

DaemonSet

- configMap을 통해 원하지 않는 로그는 필터링 할 수 있다.

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd
  namespace: kube-system
  labels:
    k8s-app: fluentd-logging
    version: v1
spec:
  selector:
    matchLabels:
      k8s-app: fluentd-logging
      version: v1
  template:
    metadata:
      labels:
        k8s-app: fluentd-logging
        version: v1
    spec:
      serviceAccount: fluentd
      serviceAccountName: fluentd
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
      containers:
      - name: fluentd
        image: fluent/fluentd-kubernetes-daemonset:v1-debian-elasticsearch
        env:
          - name:  FLUENT_ELASTICSEARCH_HOST
            value: "elasticsearch-logging"
          - name:  FLUENT_ELASTICSEARCH_PORT
            value: "9200"
          - name: FLUENT_ELASTICSEARCH_SCHEME
            value: "http"
          # Option to configure elasticsearch plugin with self signed certs
          # ================================================================
          - name: FLUENT_ELASTICSEARCH_SSL_VERIFY
            value: "true"
          # Option to configure elasticsearch plugin with tls
          # ================================================================
          - name: FLUENT_ELASTICSEARCH_SSL_VERSION
            value: "TLSv1_2"
          # X-Pack Authentication
          # =====================
          - name: FLUENT_ELASTICSEARCH_USER
            value: "elastic"
          - name: FLUENT_ELASTICSEARCH_PASSWORD
            value: "changeme"
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
        volumeMounts:
        - name: config-volume
          mountPath: /fluentd/etc/kubernetes.conf
          subPath: kubernetes.conf
        - name: varlog
          mountPath: /var/log
        # When actual pod logs in /var/lib/docker/containers, the following lines should be used.
        # - name: dockercontainerlogdirectory
        #   mountPath: /var/lib/docker/containers
        #   readOnly: true
        # When actual pod logs in /var/log/pods, the following lines should be used.
        - name: dockercontainerlogdirectory
          mountPath: /var/log/pods
          readOnly: true
      terminationGracePeriodSeconds: 30
      volumes:
      - name: config-volume
        configMap:
          name: fluentd-conf
      - name: varlog
        hostPath:
          path: /var/log
      # When actual pod logs in /var/lib/docker/containers, the following lines should be used.
      # - name: dockercontainerlogdirectory
      #   hostPath:
      #     path: /var/lib/docker/containers
      # When actual pod logs in /var/log/pods, the following lines should be used.
      - name: dockercontainerlogdirectory
        hostPath:
          path: /var/log/pods

 

참고

로그 저장소의 부하가 많아지면 정상상태로 복구하는 것이 어려워질 수 있다. 이런 상황을 사전에 방지하기 위해서는 아래와 같이 fluentd filter를 추가하여 필요한 로그만 로그 저장소에 추가해야한다.

<filter kubernetes.**>
    @type grep
    <exclude>
        key $.kubernetes.labels.app
        pattern kibana|fluentd|elasticsearch
    </exclude>
</filter>
    
# this tells fluentd to not output its log on stdout  
<match fluent.**>
    @type null
</match>

# disable kube system log 
<match kubernetes.var.log.containers.**kube-system**.log>
    @type null
</match>

출처

- [책] 쿠버네티스 완벽 가이드 마사야 아오야마 지음, 박상욱 옮김

- [fluentd in k8s]

https://github.com/fluent/fluentd-kubernetes-daemonset/blob/master/fluentd-daemonset-elasticsearch-rbac.yaml

https://blog.opstree.com/2019/12/17/collect-logs-with-fluentd-in-k8s-part-2/

 

'클라우드 컴퓨팅 > 쿠버네티스' 카테고리의 다른 글

Kubernetes Monitoring with Prometheus  (0) 2021.10.27
Helm으로 매니페스트 범용화하기  (0) 2021.10.26
Kubernetes Container Images  (0) 2021.10.24
AWS EKS 살펴보기  (0) 2021.10.23
Kubernetes Cluster Maintenance  (0) 2021.10.16

컨테이너 이미지는 애플리케이션과 모든 소프트웨어 의존성을 캡슐화하는 바이너리 데이터를 나타낸다. 컨테이너 이미지는 독립적으로 실행할 수 있고 런타임 환경에 대해 잘 정의된 가정을 만드는 실행 가능한 소프트웨어 번들이다.

 

일반적으로 파드에서 참조하기 전에 애플리케이션의 컨테이너 이미지를 생성해서 레지스트리로 푸시한다.

 

도커 레지스트리

Docker registry is a storage and distribution system for named Docker images. The same image might have multiple different versions, identified by their tags.

도커 퍼플릿 레지스트리

By default, the Docker engine interacts with DockerHub

 

도커 프라이빗 레지스트리

- 파드에 ImagePullSecrets을 명시하기 위해 시크릿을 생성하자

kubectl create secret docker-registry <name> 
--docker-server=DOCKER_REGISTRY_SERVER 
--docker-username=DOCKER_USER 
--docker-password=DOCKER_PASSWORD 
--docker-email=DOCKER_EMAIL

 

참고: 파드는 이미지 풀 시크릿을 자신의 네임스페이스에서만 참조할 수 있다. 따라서 이 과정은 네임스페이스 당 한 번만 수행될 필요가 있다.

 

- 해당 시크릿을 참조하는 파드 생성 예시

cat <<EOF > pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: foo
  namespace: awesomeapps
spec:
  containers:
    - name: foo
      image: janedoe/awesomeapp:v1
  imagePullSecrets:
    - name: docker-registry
EOF

cat <<EOF >> ./kustomization.yaml
resources:
- pod.yaml
EOF

 

이미지 이름 부분 다음에 tag 를 추가할 수 있다. 태그를 사용하면 동일한 시리즈 이미지의 다른 버전을 식별할 수 있다.

 

이미지 태그는 소문자와 대문자, 숫자, 밑줄(_), 마침표(.) 및 대시(-)로 구성된다. 이미지 태그 안에서 구분 문자(_, - 그리고 .)를 배치할 수 있는 위치에 대한 추가 규칙이 있다. 태그를 지정하지 않으면, 쿠버네티스는 태그 latest 를 의미한다고 가정한다.

 

프로덕션에서 컨테이너를 배포할 때는 latest 태그를 사용하지 않아야 한다. 실행 중인 이미지 버전을 추적하기가 어렵고 이전에 잘 동작하던 버전으로 롤백하기가 더 어렵다.
대신, v1.42.0 과 같은 의미있는 태그를 지정한다.

 

보다 정확하게 파드가 같은 버전의 이미지를 사용하게 하고 싶다면 digest를 사용할 수 있다.

image@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2

 

만약 파드가 사용하고 있는 digest를 알고 싶다면 아래 명령어를 사용하길 바란다.

kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{","}{range .status.containerStatuses[*]}{.image}{", "}{.imageID}{", "}{end}{end}' | sort

 

이미지 업데이트

디플로이먼트, 스테이트풀셋, 파드 또는 파드 템플릿은 포함하는 다른 오브젝트를 처음 만들 때 특별히 명시하지 않은 경우 기본적으로 해당 파드에 있는 모든 컨테이너의 풀(pull) 정책은 IfNotPresent로 설정된다.

 

이미지 Pull Policy

pull policy 설명
IfNotPresent the image is pulled only if it is not already present locally.
Always every time the kubelet launches a container, the kubelet queries the container image registry to resolve the name to an image digest. If the kubelet has a container image with that exact digest cached locally, the kubelet uses its cached image; otherwise, the kubelet pulls the image with the resolved digest, and uses that image to launch the container.
Never the kubelet does not try fetching the image. If the image is somehow already present locally, the kubelet attempts to start the container; otherwise, startup fails.

 

만약 항상 이미지 풀을 강제하고 싶다면, 다음 중 하나를 수행하면 된다.

  • 컨테이너의 imagePullPolicy를 Always로 설정.
  • imagePullPolicy를 생략하고 :latest를 사용할 이미지의 태그로 사용, 쿠버네티스는 정책을 Always로 설정한다.
  • imagePullPolicy와 사용할 이미지의 태그를 생략.
  • AlwaysPullImages 어드미션 컨트롤러를 활성화.
컨테이너의 imagePullPolicy 값은 오브젝트가 처음 created 일 때 항상 설정되고 나중에 이미지 태그가 변경되더라도 업데이트되지 않는다.
예를 들어, 태그가 :latest가 아닌 이미지로 디플로이먼트를 생성하고, 나중에 해당 디플로이먼트의 이미지를 :latest 태그로 업데이트하면 imagePullPolicy 필드가 Always 로 변경되지 않는다. 오브젝트를 처음 생성 한 후 모든 오브젝트의 풀 정책을 수동으로 변경해야 한다.

 

도커 이미지와 이미지 사이즈

이미지명 이미지 사이즈
scratch 최소
alpine 작다
distroless 작다
ubuntu 크다
centos 크다
Universal Base Image 크다

 


출처

- [Docker Registry] : https://www.aquasec.com/cloud-native-academy/docker-container/docker-registry/

- [책: 쿠버네티스 완벽 가이드 마사야 아오야마 지음, 박상욱 옮김]

- [컨테이너 이미지]

https://kubernetes.io/ko/docs/tasks/access-application-cluster/list-all-running-container-images/

https://kubernetes.io/docs/concepts/containers/images/#pre-pulled-images

https://kubernetes.io/ko/docs/concepts/containers/images/

Kubernetes 관리 서비스를 제공하는 대형 클라우드 업체 중 AWS EKS를 통한 k8s 클러스터 생성 과정을 살펴보자.

 

출처 : https://docs.aws.amazon.com/eks/latest/userguide

 

 

첫째, 클러스터 생성

AWS CLI 혹은 eksctl 등으로 EKS 클러스터를 할 수 있는데 eksctl를 이용한 방법을 살펴보자. 그 이유는 eksctl은 클러스터 구성에 필요한 설정을 일반적인 수준에서 알아서 관리해준다. 좀 더 자세한 클러스터 튜닝을 하고 싶다면 AWS CLI를 이용하여 클러스터를 생성하는 것을 추천한다.

 

Prerequisites

- kubectl : A command line tool for working with Kubernetes clusters.

- eksctl : A command line tool for working with EKS clusters that automates many individual tasks.

 

클러스터 생성 옵션

- name : 클러스터 이름

- version : kubernetes 버전

- managed : Node를 Amazon EC2 인스턴스로 생성

- node-type : Amazon EC2 인스턴스 유형

- region : 클러스터 리전

eksctl create cluster \
--name my-cluster \
--version 1.xx \
--node-type t2.xx \
--region us-west-2 \
--with-oidc \
--ssh-access \
--ssh-public-key your-key
--managed

 

클러스터 생성 진행상황을 확인하고 싶다면 CloudFormation을 확인해보길 바란다.

 

클러스터 삭제 역시 아주 간단하다.

eksctl delete cluster --name cluster_name

 

이렇게 eksctl를 이용해서 쿠버네티스 클러스터 생성을 아주 쉽게 완료할 수 있다.

 

둘째, 기본적으로 추가되는 노드그룹 외에 노드그룹 생성

- cluster : 클러스터 이름

- region : 클러스터 리전

- name : 노드그룹 이름

- node-type : 노드그룹 Amazon EC2 인스턴스 유형

- nodes : 노드 요청 개수

- nodes-min : 최소 노드 개수

- nodes-max : 최대 노드 개수

- managed : Node를 Amazon EC2 인스턴스로 생성

eksctl create nodegroup \
  --cluster <my-cluster> \
  --region <region-code> \
  --name <my-mng> \
  --node-type <m5.large> \
  --nodes <3> \
  --nodes-min <2> \
  --nodes-max <4> \
  --ssh-access \
  --ssh-public-key <my-key>
  --managed
  
eksctl scale nodegroup --cluster=clusterName --nodes=desiredCount --name=nodegroupName --region region --nodes-min=3 --nodes-max=6

 

기본적으로 생성된 노드그룹은 아래 내용을 포함하고 있을 것이다.

- coredns : 쿠버네티스 클러스터의 DNS 역할을 수행할 수 있는, 유연하고 확장 가능한 DNS 서버이다. 서비스디스커버리에 활용됨.

- kube-proxy : worker node 사이의 container들의 커뮤니케이션 수단 제공 

- cni : Container Network Interface

- kubelet : master node와 컨테이너 상태 등에 대해서 커뮤니케이션 및 container를 제어하는 역할

 

셋째, kubectl을 이용하여 EKS 클러스터를 관리한다.

넷째, 원하는 워크로드를 생성한 EKS 클러스터에 배포한다.

 

자동으로 생성된 VPC 네트워크 구성에 대해서 살펴보도록 하자.

 

https://aws.amazon.com/ko/quickstart/architecture/vpc/

 

VPC(Amazon Virtual Private Cloud)

1. 인터넷게이트웨이(IGW)

- 응답을 받을때 private ip로 주소변환(NAT)

- enables inbound and outbound access to the internet

- 기타

2. 보안그룹

- SSH 접근 보안 설정

- control plane과 워커 노드그룹 사이 보안 설정

- 클러스터 노드 사이 보안 설정

- CNI 보안 설정

- 기타

3. Subnet

출처 : https://medium.com/awesome-cloud/aws-vpc-difference-between-internet-gateway-and-nat-gateway-c9177e710af6

Private subnet

기본적으로 외부와 차단되어 있고, 다른 서브넷과의 연결만 가능

- 라우팅 테이블

- 네트워크 ACL

- Amazon EC2

 

Public subnet

- NAT 게이트웨이 : 인터넷에서 들어오는 트래픽을 차단. private subnet의 인터넷 요청에 대한 결과를 전달.

NAT(Network Address Translation) : IP 패킷 헤더의 IP 주소를 변경하는 기능을 뜻함. DNAT, SNAT

- 라우팅 테이블

- 네트워크 ACL

- Amazon EC2

4. 로드밸런서

5. 기타

 

이렇게 eksctl를 이용하여 AWS EKS 클러스터 생성과정을 살펴보았다. 

 

이외에 Calico를 이용하여 Networkpolicy를 적용하는 등의 설정을 통해 클러스터 보안을 향상시킬 수 있다. 참고로 클러스터 밖에서 접속하는 트래픽에 대해서는 방화벽 설정을 할 수 없다. 그 이유는 외부에서 클러스터 내부로 들어오는 Source 주소가 변경되기 때문이다.

 

https://github.com/projectcalico/calico/issues/2088#issuecomment-411796428

 


출처

- [networkpolicy from outside] : https://github.com/projectcalico/calico/issues/2088

- [AWS EKS CNI plugins] : https://docs.aws.amazon.com/eks/latest/userguide/calico.html

- [Calico on Amazon EKS] : https://docs.aws.amazon.com/eks/latest/userguide/calico.html

- [Internet Gateway and Nat gateway] : https://medium.com/awesome-cloud/aws-vpc-difference-between-internet-gateway-and-nat-gateway-c9177e710af6

- [NAT Gateway]

https://docs.aws.amazon.com/ko_kr/vpc/latest/userguide/vpc-nat-gateway.html

https://www.youtube.com/watch?v=ujXr0i5EoHE

- [Internet Gateway] : https://www.youtube.com/watch?v=u7obme-h3bc

- [kube-proxy] : https://kubernetes.io/docs/reference/command-line-tools-reference/kube-proxy/

- [CoreDNS] : https://kubernetes.io/ko/docs/tasks/administer-cluster/coredns/

- [EKS nodegroup] : https://docs.aws.amazon.com/eks/latest/userguide/create-managed-node-group.html

- [EKS nodegroup scale] : https://aws.amazon.com/ko/premiumsupport/knowledge-center/eks-worker-node-actions/

- [EKS란] : https://docs.aws.amazon.com/eks/latest/userguide/what-is-eks.html

- [EKS with eksctl] : https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html

+ Recent posts