Getting Started

Install kubectl on Linux

Note

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

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:"19", GitVersion:"v1.19.2", GitCommit:"f5743093fd1c663cb0cbc89748f730662345d44d", GitTreeState:"clean", BuildDate:"2020-09-16T13:41:02Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.3", GitCommit:"1e11e4a2108024935ecfcb2912226cedeafd99df", GitTreeState:"clean", BuildDate:"2020-10-14T12:41:49Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"}

Configure kubectl

Before you can begin operating your new Kubernetes cluster, you will need to create your team’s users in the ASERGO Dashboard. Go to Dashboard User list and configure the users.

Each user can download an automatic generated kubectl config file for your cluster(s); place this config under ~./kube.

We recommend using a plugin manager like krew to manage your plugins for kubectl. Read the Krew install instructions for more information.

Install the ‘kube-oidc’ plugin for kubectl. The configuration of the plugin is in the config file you downloaded from the dashboard. To install the plugin via krew run:

$  kubectl krew install oidc-login

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