Basic Kubernetes Commands on Docker for Windows

Learning to manage Kubernetes on a large scale can take time and effort however if you don’t know the basic commands needed you will never get to a stage where you know how to manage large scale environments.

Today, I will show the basic commands that form the building blocks to manage Kubernetes on Docker for Windows and other platforms.

Get Started

Below you will see all the commands that will show you how to start, stop and manage deployment on Kubernetes.

Start Web UI

To start the Web UI management interface, I will run the two commands below, the first one is only needed once, which installs the Web UI pods.

kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
kubectl proxy

Run a Basic container (Deployment)

In Kubernetes, we don’t run containers we run Deployments and below I will deploy a basic Nginx container with port 80 open

kubectl run --image=nginx web01 --port=80 --env="DOMAIN=cluster"

Expose Container

In Kubernetes, deploying a Container will not make it available therefore we need to expose the open port specified in the Run command above.

kubectl expose deployment web01 --port=80 --name=web01

List all deployments

To list all deployments I will use the command below

kubectl get po -a

View running Deployments

To view only running deployments I will run the command below

kubectl get pods

Attach to a running Pod

To attach to a running deployment, I will run the get nods command to find the pod name and use the attach command

kubectl get pods
kubectl attach deploymentname

Exec command on Container

To run a command against a deployment I will use the line below, in my example I will find the hostname of the container

kubectl get pods
kubectl exec web01 hostname

View logs

To view logs on a specific container, I will use the line below

kubectl get pods
kubectl logs -f web01

Delete Deployment

And finally, to delete a deployment I will use the two lines below, the first one will list all deployments and the second one will delete it

kubectl get deployment
kubectl delete deployment

Version and Cluster Info

To view my Kubernetes version number and cluster information I will use the two commands below

kubectl version
kubectl cluster-info

Posted

in

by