Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
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
Tags
more
Archives
Today
Total
관리 메뉴

클라우드 엔지니어 꿈나무

EKS autoscaling 생성 w/helm 본문

AWS

EKS autoscaling 생성 w/helm

새싹싹이 2024. 1. 3. 11:46

EKS version : 1.24

Kubernets version: 1.23.6

helm version: 3.8.2

 

<<참고>>

이전에 적용했던 yaml 파일 되돌리고 실행하기

kubectl apply -f . 

 

모니터링을 위하여 metric server 설치

kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

 

설치 확인

 

Charts.yaml

apiVersion: v2
name: game2048
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"

 

 

values.yaml 

# Default values for game2048.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

appName: "game2048"
replicaCount: 3

image:
  repository: <계정번호>.dkr.ecr.ap-northeast-2.amazonaws.com/<레지스트리명>
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: "FE9"

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

podAnnotations: {}

maxSurge: 34%
maxUnavailable: 0%

service:
  type: ClusterIP
  port: 80

ingress:
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/load-balancer-name: fastc-alb
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS": 443}]'
    alb.ingress.kubernetes.io/healthcheck-path: /
    alb.ingress.kubernetes.io/subnets: subnet-055730a1eef28f4cf, subnet-08a76f98b880aee75
    alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:ap-northeast-2:194453983284:certificate/3497f02e-c348-4ee3-a598-1fd20b239e1b
  ingressRule:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: game2048
                port:
                  number: 80
  tls:
   - hosts:
       - 1jo10000jo.link  # 실제 도메인으로 교체
     secretName: game2048-acm-tls-secret  # 임의의 시크릿 이름으로 지정

resources: 
  # We usually recommend not to specify default resources and to leave this as a conscious
  # choice for the user. This also increases chances charts run on environments with little
  # resources, such as Minikube. If you do want to specify resources, uncomment the following
  # lines, adjust them as necessary, and remove the curly braces after 'resources:'.
  limits:
     cpu: 500m
     memory: 128Mi
  requests:
     cpu: 500m
     memory: 128Mi

autoscaling:
  enabled: true
  minReplicas: 2
  maxReplicas: 10
  targetCPUUtilizationPercentage: 20
  # targetMemoryUtilizationPercentage: 80

nodeSelector:
  nodeType: service-2023

tolerations:
  - key: service
    operator: "Equal"
    value: "true"
    effect: "NoSchedule"

affinity: {}

 

 

 

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.appName }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "game2048.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: {{ .Values.maxSurge }}
      maxUnavailable: {{ .Values.maxUnavailable }}
  selector:
    matchLabels:
      {{- include "game2048.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "game2048.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: {{ .Values.service.port }}
              protocol: TCP
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}

 

hpa.yaml (eks 1.25 / 1.24 버전은 하기 접은 글 참고)

{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: {{ include "game2048.fullname" . }}
  labels:
    {{- include "game2048.labels" . | nindent 4 }}
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ include "game2048.fullname" . }}
  minReplicas: {{ .Values.autoscaling.minReplicas }}
  maxReplicas: {{ .Values.autoscaling.maxReplicas }}
  metrics:
    {{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
    - type: Resource
      resource:
        name: cpu
        targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
    {{- end }}
    {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
    - type: Resource
      resource:
        name: memory
        targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
    {{- end }}
{{- end }}

 

ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ .Values.appName }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "game2048.labels" . | nindent 4 }}
  {{- with .Values.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  {{- with .Values.ingress.ingressRule }}
  rules:
    {{- toYaml . | nindent 4 }}
  {{- end }}

 

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: {{ .Values.appName }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "game2048.labels" . | nindent 4 }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: {{ .Values.service.port }}
      protocol: TCP
      name: http
  selector:
    {{- include "game2048.selectorLabels" . | nindent 4 }}

 

helm install -f <yaml 파일> <생성할 차트 이름> <차트 위치>

 helm install -f values.yaml game2048 . --create-namespace (namespace 같이 생성)

 

부하 테스트를 위하여 apache-bench 설치

apt install apache2-utils -y

 

부하테스트

부하테스트 전 상태

 

 

ab -n 100000 -c 1000 <alb DNS>/ (슬래시 필수)

ab -n 100000 -c 1000 recac-alb-914413904.ap-northeast-2.elb.amazonaws.com/

 

pod 생성 확인

 

 

node 생성 확인