- EKS에서 userdata를 설정하는 방법
- AL2023 EKS AMI 기준 으로 설명
- Managed NodeGroup은 EKS managed node group의 launch template에서 user data를 설정합니다.
- userdata 파일을 확인합니다. user data는 EC2인스턴스가 실행 될 때, nginx를 설치하고 실행합니다. user data는 MIME포맷으로 작성되어 있습니다.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="
--==MYBOUNDARY==
Content-Type: text/x-shellscript; charset="us-ascii"
#!/bin/bash
dnf update -y
dnf install -y nginx
systemctl start nginx
systemctl enable nginx
--==MYBOUNDARY==--
user data가 설정된 EC2 인스턴스가 EKS 클러스터에 조인되었는지 확인합니다.
kubectl get node
- EC2인스턴스 콘솔에서 이전 단계에서 확인한 user data가 설정되었는지 확인합니다.
- EC2 인스턴스 쉘에서 nginx가 실행되고 있는지 확입합니다.
systemctl status nginx
kubectl apply -f ./manifests/karpenter_config
$ kubectl get EC2NodeClass,nodepool
NAME READY AGE
ec2nodeclass.karpenter.k8s.aws/example True 63s
NAME NODECLASS NODES READY AGE
nodepool.karpenter.sh/example example 1 True 5m27s
cat ./manifests/karpenter_config/nodeclass.yaml
...생략
userData: |
#!/bin/bash
dnf update -y
dnf install -y nginx
systemctl start nginx
systemctl enable nginx
- karpenter node를 생성하기 위한 더미 pod 배포
kubectl apply -f ./manifests/inflate_deployment.yaml
$ kubectl get nodeclaims
NAME TYPE CAPACITY ZONE NODE READY AGE
example-hbs97 t3a.2xlarge spot ap-northeast-2c ip-10-0-101-53.ap-northeast-2.compute.internal True 2m44s
- karpenter node가 Ready인지 확인
$ kubectl get node
NAME STATUS ROLES AGE VERSION
ip-10-0-101-53.ap-northeast-2.compute.internal Ready <none> 2m15s v1.30.6-eks-94953ac
- EC2 인스턴스 쉘에서 nginx가 실행되고 있는지 확입합니다.
systemctl status nginx