출처

로컬에 kops 설치

# kops v1.20.0 설치
curl -LO <https://github.com/kubernetes/kops/releases/download/v1.20.0/kops-darwin-amd64>

# kops 바이너리를 실행 가능하게 만듦
chmod +x kops-darwin-amd64

# kops 바이너리를 사용자의 PATH로 이동
sudo mv kops-darwin-amd64 /usr/local/bin/kops

# homebrew로 kops 설치
brew update && brew install kops

S3 버킷에 쿠버네티스 클러스터의 설정 정보 저장

# S3 버킷 생성
aws s3api create-bucket \\
--bucket sulsul-k8s-bucket \\
--create-bucket-configuration LocationConstraint=ap-northeast-2

# 해당 S3 버킷의 버저닝 기록
aws s3api put-bucket-versioning \\
--bucket sulsul-k8s-bucket \\
--versioning-configuration Status=Enabled

쿠버네티스 클러스터 이름과 S3 버킷 이름을 shell 환경 변수로 설정

export NAME=sulsulcluster.k8s.local
export KOPS_STATE_STORE=s3://sulsul-k8s-bucket

쿠버네티스를 설치할 EC2 인스턴스에 배포될 SSH 키를 생성

셸의 현재 디렉토리에 비밀키와 공개키가 생성

ssh-keygen -t rsa -N "" -f ./id_rsa

클러스터 설정 파일 생성

kops create cluster \\
--zones ap-northeast-2a \\
--networking calico \\
--ssh-public-key ./id_rsa.pub \\
$NAME

Error: [metadata.name: Invalid value: "sulsul_cluster.k8s.local": a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'), objectMeta.name: Invalid value: "sulsul_cluster.k8s.local": Cluster Name must be a valid DNS name (e.g. --name=mycluster.myzone.com) errors: a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')]