- 본 가이드는 OS는 ubuntu에서 진행했습니다.
- OS에 따라 설치 방법이 다를 수 있는 점 참고해 주세요.
- IAM 권한이 root 권한이므로 EKS를 위해 권한 설정하는 과정은 넣지 않았습니다.
- aws에서 제공하는 가이드를 기준으로 진행했습니다.
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ sudo ./aws/install
$ $ aws --version
aws-cli/2.7.33 Python/3.9.11 Linux/5.15.0-1019-aws exe/x86_64.ubuntu.20 prompt/off
$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: ap-northeast-2
Default output format [None]: json
$ kubectl version | grep Client | cut -d : -f 5
$ curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.23.7/2022-06-29/bin/linux/amd64/kubectl
$ chmod +x ./kubectl
$ mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
$ kubectl version --short --client
Client Version: v1.23.7-eks-4721010
$ aws cloudformation create-stack \
--region ap-northeast-2 \
--stack-name paasta-ta-vpc \
--template-url https://s3.us-west-2.amazonaws.com/amazon-eks/cloudformation/2020-10-29/amazon-eks-vpc-private-subnets.yaml
$ vi eks-cluster-role-trust-policy.json
---
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "eks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
$ aws iam create-role \
--role-name EKSClusterRole \
--assume-role-policy-document file://"eks-cluster-role-trust-policy.json"
$ aws iam attach-role-policy \
--policy-arn arn:aws:iam::aws:policy/AmazonEKSClusterPolicy \
--role-name EKSClusterRole
$ aws eks update-kubeconfig --region ap-northeast-2 --name paasta-ta-cluster
Updated context arn:aws:eks:ap-northeast-2:192199172625:cluster/paasta-ta-cluster in /home/ubuntu/.kube/config
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.100.0.1 <none> 443/TCP 19m
$ vi node-role-trust-policy.json
---
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
$ aws iam create-role \
--role-name EKSNodeRole \
--assume-role-policy-document file://"node-role-trust-policy.json"
$ aws iam attach-role-policy \
--policy-arn arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy \
--role-name EKSNodeRole
$ aws iam attach-role-policy \
--policy-arn arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly \
--role-name EKSNodeRole
$ aws iam attach-role-policy \
--policy-arn arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy \
--role-name EKSNodeRole
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
ip-192-168-240-95.ap-northeast-2.compute.internal Ready <none> 2m42s v1.23.9-eks-ba74326
ip-192-168-3-28.ap-northeast-2.compute.internal Ready <none> 2m55s v1.23.9-eks-ba74326
$ vi spring-music-sample.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-music
namespace: default
spec:
selector:
matchLabels:
app: spring-music
replicas: 1
template:
metadata:
labels:
app: spring-music
spec:
containers:
- name: spring-music
image: paastaccc/spring-music-sample:0.1
imagePullPolicy: Always
resources:
requests:
cpu: 500m
memory: 200Mi
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: spring-music-service
spec:
ports:
ports:
- port: 8083
protocol: TCP
targetPort: 8080
selector:
app: spring-music
type: NodePort
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
spring-music-78cb987c9f-mg4l7 1/1 Running 0 21s
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.100.0.1 <none> 443/TCP 85m
spring-music-service NodePort 10.100.164.35 <none> 8083:30223/TCP 40s
$ kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
ip-192-168-240-95.ap-northeast-2.compute.internal Ready <none> 9m49s v1.23.9-eks-ba74326 192.168.240.95 <none> Amazon Linux 2 5.4.209-116.367.amzn2.x86_64 docker://20.10.17
ip-192-168-3-28.ap-northeast-2.compute.internal Ready <none> 10m v1.23.9-eks-ba74326 192.168.3.28 13.125.223.101 Amazon Linux 2 5.4.209-116.367.amzn2.x86_64 docker://20.10.17
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.100.0.1 <none> 443/TCP 85m
spring-music-service NodePort 10.100.164.35 <none> 8083:30223/TCP 40s
참고
access key랑 secret key를 인터넷에 함부로 게시하면 위험해요. 누군가가 그 계정으로 sue님의 aws 계정에서 마음대로 할 수 있게 되거든요. key는 지우시는게 좋겠어요.