EKS는 aws 클라우드에서 쿠버네티스를 사용할 수 있도록 지원하는 서비스이다.
eksctl 명령을 이용해서 AWS EKS 생성하기
1. Bastion 호스트 준비
Bastion Host란 침입 차단 소프트웨어가 설치되어 내부와 외부 네트워크 사이에서 일종의 게이트 역할을 수행하는 호스트를 뜻함.
참고 : https://aws.amazon.com/ko/quickstart/architecture/linux-bastion/
https://blog.naver.com/pentamkt/221034903499
AWS EC2 instance를 생성해서 Bastion Server로 사용한다.
2. Bastion Host(ubuntu Linux)에 AWS CLI 관리툴인 aws
참고: https://docs.aws.amazon.com/ko_kr/cli/latest/userguide/install-cliv2-linux.html
$ sudo apt-get install -y unzip
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ sudo ./aws/install
You can now run: /usr/local/bin/aws --version
$ aws --version
aws-cli/2.7.11 Python/3.9.11 Linux/5.13.0-1029-aws exe/x86_64.ubuntu.20 prompt/off
3. Bastion Host(ubuntu Linux)에 EKS설치/운영 툴인 eksctl 설치
참고: https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/eksctl.html
$ curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
$ sudo mv /tmp/eksctl /usr/local/bin
$ eksctl version
0.103.0
4. Bastion Host(ubuntu Linux)에 k8s 관리툴인 kubectl 설치
참고: https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/install-kubectl.html
$ curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.21.2/2021-07-05/bin/linux/amd64/kubectl
$ chmod +x ./kubectl
$ mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
$ echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc
$ kubectl version --short --client
Client Version: v1.19.6-eks-49a6c0
5. AWS IAM 생성하기
링크: aws.amazon.com - root 로그인후 IAM 생성
사용자이름(User name*) : eks-mng-user
프로그래밍 방식(Programmatic access) 선택
기존 정책(Attach existing policies directly) : AdministratorAccess
태그 추가(Add tags (optional)) - <SKIP>
[사용자만들기(Create User)] 버튼 클릭
사용자 생성되면 csv다운로드 -액세스ID/엑세스키
6. Bastion Host(ubuntu)에서 aws 관리할수 있도록 aws 계정(eks-mng-user) 등록
$ aws configure
AWS Access Key ID [None]: AKIASJ...E37V
AWS Secret Access Key [None]: XLzhAqt...7g
Default region name [None]: ap-northeast-2
Default output format [None]: <ENTER>
$ cat .aws/config
[default]
region = ap-northeast-2
$ cat .aws/credentials
[default]
aws_access_key_id = AKIASJ...E37V
aws_secret_access_key = XLzhAq...7g
잘 연결됐는지 확인
$ aws sts get-caller-identity
{
"UserId": "AID...KS26",
"Account": "15..75",
"Arn": "arn:aws:iam::158208647875:user/k8suser-console"
}
7. EKS 구성
참고: https://docs.aws.amazon.com/ko_kr/eks/latest/userguide/getting-started-eksctl.html
EKS요금 시간당 0.10USD + t3.medium 시간 0.416 *2 USD
[Managed nodes – Linux] 탭 선택후 사용설명확인
eksctl 명령을 실행해서 Amazon EKS 클러스터를 생성한다.
$ eksctl create cluster \
--name k8s-demo \
--region ap-northeast-2 \
--with-oidc \
--ssh-access \
--ssh-public-key public-ec2-keypair \
--nodes 3 \
--node-type t3.medium \
--node-volume-size=20 \
--managed
참고: Amazon Elastic Kubernetes Service(Amazon EKS)에서 OpenID Connect(OIDC) 호환 자격 증명 공급자를 Kubernetes 클러스터에 대한 사용자 인증 옵션으로 사용할 수 있다.
OIDC 인증을 사용하면 직원 계정의 생성, 활성화 및 비활성화에 대한 조직의 표준 절차를 사용하여 EKS 클러스터에 대한 사용자 액세스를 관리할 수 있다.
https://aws.amazon.com/ko/about-aws/whats-new/2021/02/amazon-eks-clusters-support-user-authentication-oidc-compatible-identity-providers/
CloudFormation으로 생성되기 때문에 aws에서 cloudformation으로 확인해본다.
생성되는 시간이 20분정도 걸린다.
...
- aws에서 확인 : CloudFormation 검색 후 확인
8. 설치완료되면 다음과 같이 설치 결과 확인하고, CLI 명령어 자동완성 기능을 추가
- kubectl 명령으로 설치결과 확인
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
ip-192-168-38-198.ap-northeast-2.compute.internal Ready <none> 28m v1.19.6-eks-49a6c0
ip-192-168-4-22.ap-northeast-2.compute.internal Ready <none> 28m v1.19.6-eks-49a6c0
ip-192-168-82-229.ap-northeast-2.compute.internal Ready <none> 28m v1.19.6-eks-49a6c0
CLI 명령어 완성기능 추가
$ source <(kubectl completion bash)
$ echo "source <(kubectl completion bash)" >> ~/.bashrc
9. 간단한 실행 실습
워커 노드 정보 보기
$ kubectl get nodes -o wide
Pod 배포 TEST. nginx 컨테이너 5개 실행하고 결과 확인
$ kubectl create deployment webtest --image=nginx:1.14 --port=80 --replicas=5
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
webtest-fdf54587f-8mfrz 1/1 Running 0 28s 192.168.10.139 ip-192-168-2-91.ap-northeast-2.compute.internal <none> <none>
webtest-fdf54587f-d4pjc 1/1 Running 0 28s 192.168.39.104 ip-192-168-56-22.ap-northeast-2.compute.internal <none> <none>
webtest-fdf54587f-dqg55 1/1 Running 0 28s 192.168.13.27 ip-192-168-2-91.ap-northeast-2.compute.internal <none> <none>
webtest-fdf54587f-hs8zd 1/1 Running 0 28s 192.168.77.185 ip-192-168-70-30.ap-northeast-2.compute.internal <none> <none>
webtest-fdf54587f-pn549 1/1 Running 0 28s 192.168.83.249 ip-192-168-70-30.ap-northeast-2.compute.internal <none> <none>
nginx 웹서버에 클라이언트 접속 가능하도록 구성하고 간단히 테스트한다.
$ kubectl expose deployment webtest --port=80 --type=LoadBalancer
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.100.0.1 <none> 443/TCP 33h
webtest LoadBalancer 10.100.222.89 ab5190278c9ac491cb45a4bc42a6d689-1608401336.ap-northeast-2.elb.amazonaws.com 80:30331/TCP 31s
1분정도 후에 웹브라우저를 통해 웹서버 연결되는지 확인
http://ab5190278c9ac491cb45a4bc42a6d689-1608401336.ap-northeast-2.elb.amazonaws.com
10. 모든 실습이 끝났고, 더이상 EKS 사용하지 않는다면 아래 명령으로 삭제한다. EKS, EC2 모두 과금이 되기 때문이다.
$ eksctl delete cluster --name k8s-demo
'따배클' 카테고리의 다른 글
[따배클] 2. EKS에서 EFS를 공유 스토리지로 사용하는 웹서버 띄우기 (0) | 2022.11.14 |
---|