Tuan-Anh Tran

Getting started with Kubernetes

Posted on October 28, 2016  •  1 minutes  • 181 words

Just some of my notes while learning about Kubernetes. I use Google Compute Engine to install mine.

Installation

To install Kubernetes, it’s as easy as copy and paste the below command

curl -sS https://get.k8s.io | bash

If you want to customize some default options, you can edit environment variables

curl -sS https://get.k8s.io | MULTIZONE=true KUBERNETES_PROVIDER=gce KUBE_GCE_ZONE=asia-east1-b NUM_NODES=4 bash

There’re more environment variables that you can take a look in kubernetes/cluster/gce/config-default.sh

It’s recommended to export it to environment instead of passing it to the command as above as taking the cluster down will be easier.

export KUBERNETES_PROVIDER=gce
export KUBE_GCE_ZONE=asia-east1-b
export NODE_SIZE=n1-highcpu-2
export MULTIZONE=true
export NUM_NODES=2
export KUBE_AUTOSCALER_MIN_NODES=2
export KUBE_AUTOSCALER_MAX_NODES=10
export KUBE_ENABLE_CLUSTER_AUTOSCALER=true
export PREEMPTIBLE_NODE=true

Add more nodes to cluster

KUBE_USE_EXISTING_MASTER=true KUBERNETES_PROVIDER=gce KUBE_GCE_ZONE=asia-east1-b NUM_NODES=2 ./kube-up.sh

Bring down cluster

KUBERNETES_PROVIDER=gce KUBE_GCE_ZONE=asia-east1-b ./kube-down.sh

Deploying applications on Kubernetes

We use Docker at work and deploying Docker containers in Kubernetes is a breeze.

docker build -t gcr.io/$PROJECT_ID/app-name:v1 .
gcloud docker push gcr.io/$PROJECT_ID/app-name:v1

# update
kubectl rolling-update <replication-controller> --image=gcr.io/$PROJECT_ID/app-name:v2

Expose the service to external

kubectl expose deployment <deployment-name> --type="LoadBalancer"

Enable autoscale

kubectl autoscale rc <replication-controller> --min 3 --max=10 --cpu-percent=60
Follow me

Here's where I hang out in social media