Skip to content

KOPS — AWS

Install kubectl

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

Install kops

curl -LO 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-linux-amd64
sudo mv kops-linux-amd64 /usr/local/bin/kops

Install AWS CLI

https://docs.aws.amazon.com/pt_br/cli/latest/userguide/installing.html

Setup IAM user

Reference

Required policies:

  • AmazonEC2FullAccess
  • AmazonRoute53FullAccess
  • AmazonS3FullAccess
  • IAMFullAccess
  • AmazonVPCFullAccess

Create IAM user from the command line

/root/.local/bin/aws iam create-group --group-name kops

/root/.local/bin/aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonEC2FullAccess --group-name kops
/root/.local/bin/aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonRoute53FullAccess --group-name kops
/root/.local/bin/aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonS3FullAccess --group-name kops
/root/.local/bin/aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/IAMFullAccess --group-name kops
/root/.local/bin/aws iam attach-group-policy --policy-arn arn:aws:iam::aws:policy/AmazonVPCFullAccess --group-name kops

/root/.local/bin/aws iam create-user --user-name kops
/root/.local/bin/aws iam add-user-to-group --user-name kops --group-name kops

iam create-access-key --user-name kops

You should record the SecretAccessKey and AccessKeyID in the returned JSON output, and then use them below:

# configure the aws client to use your new IAM user
aws configure           # Use your new access and secret key here
aws iam list-users      # you should see a list of all your IAM users here

# Because "aws configure" doesn't export these vars for kops to use, we export them now
export AWS_ACCESS_KEY_ID=$(aws configure get aws_access_key_id)
export AWS_SECRET_ACCESS_KEY=$(aws configure get aws_secret_access_key)

Create public key

ssh-keygen

Amazon S3 bucket for the Kubernetes state store

aws s3api create-bucket --bucket kubernetes-BUCKET-NAME  # need to specify the zone

Versioning the bucket

aws s3api put-bucket-versioning --bucket kubernetes-BUCKET-NAME --versioning-configuration Status=Enabled

DNS

Enable "auto dns" in cluster creation: .k8s.local. The only requirement to trigger this is to have the cluster name end with .k8s.local.

Create Cluster

kops create cluster --zones us-east-2c ${NAME}
kops update cluster ${NAME} --yes

Create HA Cluster

https://github.com/kubernetes/kops/blob/master/docs/high_availability.md