티스토리 뷰

728x90
반응형

kops 명령어 설치

$ wget -O kops https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64
$ chmod +x ./kops
$ sudo mv ./kops /usr/local/bin/
$ kops version



kubectl 명령어 설치

$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
$ sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
$ kubectl version --client

kubectl client만 정상적으로 버전이 뜨면된다. kops를 통해서 클러스터가 구축이 되면 client, server가 모두 정상적으로 작동하게 된다.



AWS CLI 설치

$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ sudo apt-get install unzip -y
$ unzip awscliv2.zip
$ sudo ./aws/install
$ aws --version



AWS IAM 계정 생성

다음 정책이 있는 엑세스 키 방식의 IAM 계정을 생성

image



aws configure

aws cli 사용을 위해 위에서 만든 계정 정보 저장

$ aws configure
AWS Access Key ID [****************IUXB]: 
AWS Secret Access Key [****************ismP]: 
Default region name [ap-northeast-2]: ap-northeast-2
Default output format [json]: json



s3

클러스터 정보를 저장할 s3 버킷을 생성하고, versioning 기능을 활성화

$ aws s3api create-bucket \
--bucket s3-test-k8s-ihpark-001 \
--region ap-northeast-2 \
--create-bucket-configuration LocationConstraint=ap-northeast-2

$ aws s3api put-bucket-versioning  \
--bucket s3-test-k8s-ihpark-001  \
--versioning-configuration Status=Enabled



환경 변수 설정

# vi ~/.bashrc
export AWS_ACCESS_KEY_ID=$(aws configure get aws_access_key_id)
export AWS_SECRET_ACCESS_KEY=$(aws configure get aws_secret_access_key)
export NAME=ihparkcluster.k8s.local
# {하고싶은 이름}.k8s.local로 쓰기
export KOPS_STATE_STORE=s3://s3-test-k8s-ihpark-001
# s3 bucket 이름
$ . ~/.bashrc



클러스터 접속용 ssh 키페어 생성

$ cd ~/.ssh
$ ssh-keygen
# 파일 이름 입력, 비번 입력은 그냥 엔터



kops create

kops create로 클러스터 생성을 위한 설정을 만든다.

$ kops create cluster --master-zones ap-northeast-2a \
--zones ap-northeast-2a,ap-northeast-2c \
--state s3://s3-test-k8s-ihpark-001 \
--topology public \
--networking calico \
--master-size t3a.small \
--master-count 1 \
--node-size t3a.micro \
--node-count 1 \
--cloud aws \
$NAME



kops secret

kops secret 명령어로 키페어를 등록한다.

$ kops create secret --name $NAME sshpublickey admin -i ~/.ssh/test_k8s_ihpark-001_rsa.pub



kops update

kops update 명령어로 실제로 클러스터를 생성한다.

$ kops update cluster --name $NAME
# 화면 출력
$ kops update cluster --name $NAME --yes
# 실제 적용



클러스터 실제 생성 여부 확인

$ kops validate cluster --name $NAME

unexpected error during validation: error listing nodes: Unauthorized 에러뜨면

$ kops export kubecfg --admin



클러스터 삭제

$ kops delete cluster --name $NAME
$ kops delete cluster --name $NAME --yes



참고

클러스터내의 오브젝트들을 살리고 인스턴드만 중지하려면 yaml 파일을 수정하고 update해줘야 한다.
https://stackoverflow.com/questions/53204326/kops-pause-cluster-should-bring-ec2-instance-cluster-in-stopped-state

728x90
반응형
댓글
반응형
250x250
글 보관함
최근에 달린 댓글
«   2024/04   »
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
Total
Today
Yesterday
링크