[AWS] EKS 시작하기(1) - 사전 준비과정 (ECR & Tools)
ECR에 도커 이미지 PUSH
IAM User 생성 (access key / secret key 발급)
사전 준비
kubectl 설치
$ curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 47.8M 100 47.8M 0 0 10.1M 0 0:00:04 0:00:04 --:--:-- 10.9M
$ curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/darwin/amd64/kubectl
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 47.8M 100 47.8M 0 0 9.9M 0 0:00:04 0:00:04 --:--:-- 10.9M
$ ls -al ./kubectl
-rw-r--r-- 1
$ chmod +x ./kubectl
-rwxr-xr-x
$ sudo mv ./kubectl /usr/local/bin/kubectl
$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.0", GitCommit:"9e991415386e4cf155a24b1da15becaa390438d8", GitTreeState:"clean", BuildDate:"2020-03-25T14:58:59Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"darwin/amd64"}
aws key 설정
$ aws configure
AWS Access Key ID [****************CXSA]: A**********************
AWS Secret Access Key [****************SypQ]: r********************************************
Default region name [us-east-1]: ap-northeast-2
Default output format [text]:
eksctl 설치
$ 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
awscli 업데이트
$ pip3 install --upgrade --user awscli
웹 어플리케이션 도커 빌드
node.js 데모 서버 생성
// index.js
const express = require('express');
const app = express();
const port = 3000;
app.get('/', (req, res) => res.send('Hello form Node.js Server'));
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`));
express 모듈 추가
// package.json
{
"name": "eks",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
Dockerfile 생성
FROM node:10
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "node", "index.js" ]
빌드
$ docker build -t webapp .
확인
$ docker images
ECR 생성
ECR에 PUSH
명령어
$ aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin 000000000000.dkr.ecr.ap-northeast-2.amazonaws.com
$ docker tag webapp:latest 0000000000000.dkr.ecr.ap-northeast-2.amazonaws.com/eks-demo:latest
$ docker push 00000000000.dkr.ecr.ap-northeast-2.amazonaws.com/eks-demo:latest
확인
https://towardsdatascience.com/kubernetes-application-deployment-with-aws-eks-and-ecr-4600e11b2d3c