What is Kubernetes?
The name Kubernetes has its origins from the original Greek term for helmsman or pilot. Kubernetes, or ‘k8s’ (pronounced “Kate’s”) as it’s sometimes referred to, is an open-source software tool that was originally created by Google and is now being maintained by the Cloud Native Computing Foundation. Kubernetes is used for arranging and coordinating containers that an application needs to run into easy to handle groups.
In order to manage your Kubernetes cluster effectively, we recommend using kubectl as the command-line tool of choice. Basically, kubectl communicates with the master node (or server) which in turn submits those commands to the worker nodes to manage the cluster.
The Kubernetes cluster consists of two basic types of resources;
- Master server – a master server organizes the cluster
- Node server – Nodes are the workers that contain and run the applications
Each node contains a Kubelet, which is the agent for managing the node and communicating with the master. You can use kubectl to deploy, explore, review and remove Kubernetes objects (like nodes, images or containers).
Let’s next look at setting up kubectl.
In order to setup kubectl, we will need the following:
- A working internet connection
- The cURL or wget utilities installed
- Basic knowledge of the Linux command line
On an Ubuntu 16.04 LTS server, here are the commands to use if logged in as root to install kubectl:
apt-get update && sudo apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | tee -a /etc/apt/sources.list.d/kubernetes.list
apt-get install -y kubectl
Kubectl Commands for Basic Kubernetes Functions
Now that we have kubectl up and running, let’s review a few of the basic commands available. Here are the five most basic commands we will be reviewing along with their fundamental definition:
- kubectl create – the create command constructs a resource from a configuration file or stdin (or standard input). A resource is defined as “something that can be “requested by”, “allocated to”, “or consumed by” a pod or container.”
- kubectl get – the get command displays a table of the most relevant information about one or multiple relevant resources.
- kubectl run – the run command will kickoff one or more instances of a container in the cluster.
- kubectl expose – the expose command will start to load balance inbound traffic across your running instances. This command can also create a High Availability proxy for the client to access the running containers from outside the cluster.
- kubectl delete – the delete command removes defined resources by
- resources and names
- resources and label selector
Kubectl App Management
- kubectl edit – Alters the characteristics of a resource on a server using the default editor.
- kubectl apply – Applies a change to a resource from a file or stdin.
- kubectl label – Adds or updates a specific attribute to specifically identify an object
Working with Apps Using Kubectl
- kubectl exec – Runs a command on a container in a pod
- kubectl logs – Prints a container log
- kubectl describe – Displays the status or state of the resources.
Kubectl Cluster Management
- kubectl cluster-info – Displays information about the master and services in the cluster.
- kubectl drain – removes pods in preparation for maintenance
- kubectl certificate – Approves a CSR or certificate signing request
Kubectl Settings and Usage
- kubectl api-resources (eg. Pods and Services) – Lists all of the supported resources and their shortnames, API grouping, if namespaced, and Kind
- kubectl config – Changes or alters kubeconfig files
- kubectl version – Displays the Kubernetes version
These are just some of the many basic command examples that are available for use in setting up and maintaining your Kubernetes environment.