Getting Started

Install kubectl on Linux

Download the latest version of 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

Make the kubectl program executable

$ chmod +x ./kubectl

Move kubectl in to your local bin folder

$ sudo mv ./kubectl /usr/local/bin/kubectl

Test and ensure you have installed the latest version of kubectl

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.3", GitCommit:"2d3c76f9091b6bec110a5e63777c332469e0cba2", GitTreeState:"clean", BuildDate:"2019-08-19T11:05:50Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}

Note

For more information on how to install kubectl on other operating systems see here

Launch your application

Create a namespace for the application

$ kubectl create namespace my-new-app

Start your application in the namespace

$ kubectl -n my-new-app apply -f \
        https://asergo.com/knowledge-base/kubernetes/deploy/my-new-app-dp.yml
# https://asergo.com/knowledge-base/kubernetes/deploy/my-new-app-dp.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-new-app-deployment
spec:
  selector:
    matchLabels:
      app: my-new-app
  replicas: 1
  template:
    metadata:
      labels:
        app: my-new-app
    spec:
      containers:
      - name: my-new-app
        image: nginx:1.7.9
        ports:
        - containerPort: 80

Check application rollout status

$ kubectl -n my-new-app get deploy my-new-app-deployment
NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
my-new-app-deployment   1/1     1            1           3s

Scale your application

To scale the application to run more than 1 replication

$ kubectl -n my-new-app scale deployment.v1.apps/my-new-app-deployment --replicas=5
deployment.apps/my-new-app-deployment scaled

Check application rollout status

$ kubectl -n my-new-app get deploy my-new-app-deployment
NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
my-new-app-deployment   5/5     5            5           12m

Application logs

Tail log of pod

$ kubectl -n my-new-app logs -f my-new-app-deployment-689cb78dbd-6ff7l

It is also possible to tail logs of all pods under the same label

$ kubectl -n my-new-app logs -f -l app=my-new-app