Cheat Sheet

Useful Kops tricks.

Enable autocomplete

source <(kops completion bash)

Create cluster

Export your AWS credentials.

export AWS_ACCESS_KEY_ID=ThyFreeFolk
export AWS_SECRET_ACCESS_KEY=YouShallNotPass
export EC2_REGION=ap-southeast-2
export AWS_DEFAULT_REGION=ap-southeast-2

Create a bucket, for example STATE-BUCKET.

Then create your cluster.

kops create cluster \
  --zones=ap-southeast-2a \
  --master-size=t2.small \
  --node-size=t2.medium \
  --node-count=1 \
  --admin-access=0.0.0.0/0 \
  --authorization=AlwaysAllow \
  --cloud=aws \
  --name=YOUR-CLUSTER-NAME \
  --state=s3://STATE-BUCKET
  --yes

This setup is not suitable for production environments. admin-access and authorization are wide open.

Validate cluster

kops validate cluster

Get cluster credentials

Get admin password

kops get secrets kube --type secret -oplaintext

Get token

kubectl -n kube-system \
  describe secret \
  $(kubectl -n kube-system \
  get secret | awk '/^deployment-controller-token-/{print $1}') | \
  awk '$1=="token:"{print $2}'

Upgrade Kubernetes version

Before you begin

Double check your Kops and Kubernetes version compatibility.

DO NOT upgrade to a Kubernetes version unsuported by your Kops version

Check Kops Compatibility Matrix:

If you don’t know yet, get your cluster’s name:

kubectl config get-clusters

Let’s suppose your cluster name is my-cluster-name.

Export an environment variable with your cluster name:

export NAME=my-cluster-name

Edit cluster’s config:

kops edit cluster $NAME

You cluster’s config will be opened in your text editor. Find and replace the config kubernetesVersion, for example:

From:

kubernetesVersion: 1.6.0

To:

kubernetesVersion: 1.9.9

Save and exit.

Preview changes:

kops update cluster $NAME

Apply changes:

kops update cluster $NAME --yes

Preview update:

kops rolling-update cluster $NAME

Roll update:

kops rolling-update cluster $NAME --yes

Automated update

Alternatively you can run Kops auto update:

kops upgrade cluster $NAME
kops upgrade cluster $NAME --yes
kops update cluster $NAME
kops update cluster $NAME --yes

Upgrade uses the latest Kubernetes version considered stable by kops, defined in https://github.com/kubernetes/kops/blob/master/channels/stable

References

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

Last updated