Welcome to Kubernetes for Developers! This chapter starts off by helping you get the tools installed that will allow you to take advantage of Kubernetes in your development. Once installed, we will interact with those tools a bit to verify that they are functional. Then, we will review some of the basic concepts that you will want to understand to effectively use Kubernetes as a developer. We will cover the following key resources in Kubernetes:
- Container
- Pod
- Node
- Deployment
- ReplicaSet
In addition to your usual editing and programming tools, you will want to install the software to leverage Kubernetes. The focus of this book is to let you do everything on your local development machine, while also allowing you to expand and leverage a remote Kubernetes cluster in the future if you need more resources. One of Kubernetes' benefits is how it treats one or one hundred computers in the same fashion, allowing you to take advantage of the resources you need for your software, and do it consistently, regardless of where they're located.
The examples in this book will use command-line tools in a Terminal on your local machine. The primary one will be kubectl
, which communicates with a Kubernetes cluster. We will use a tiny Kubernetes cluster of a single machine running on your own development system with Minikube. I recommend installing the community edition of Docker, which makes it easy to build containers for use within Kubernetes:
kubectl
:kubectl
(how to pronounce that is an amusing diversion within the Kubernetes community) is the primary command-line tool that is used to work with a Kubernetes cluster. To installkubectl
, go to the pagehttps://kubernetes.io/docs/tasks/tools/install-kubectl/and follow the instructions relevant to your platform.
minikube
: To install Minikube, go to the page https://github.com/kubernetes/minikube/releasesand follow the instructions for your platform.
docker
: To install the community edition of Docker, go to the webpage https://www.docker.com/community-editionand follow their instructions for your platform.
In addition to kubectl
, minikube
, and docker
, you may want to take advantage of additional helpful libraries and command-line tools.
jq
is a command-line JSON processor that makes it easy to parse results in more complex data structures. I would describe it as grep's cousin that's better at dealing with JSON results. You can install jq
by following the instructions at https://stedolan.github.io/jq/download/. More details on what jq
does and how to use it can also be found at https://stedolan.github.io/jq/manual/.
Once Minikube and Kubectl are installed, get a cluster up and running. It is worthwhile to know the versions of the tools you're using, as Kubernetes is a fairly fast-moving project, and if you need to get assistance from the community, knowing which versions of these common tools will be important.
The versions of Minikube and kubectl
I used while writing this are:
- Minikube: version 0.22.3
kubectl
: version 1.8.0
You can check the version of your copy with the following commands:
This will output a version:
If you haven't already done so while following the installation instructions, start a Kubernetes with Minikube. The simplest way is using the following command:
This will download a virtual machine image and start it, and Kubernetes on it, as a single-machine cluster. The output will look something like the following:
Minikube will automatically create the files needed for kubectl
to access the cluster and control it. Once this is complete, you can get information about the cluster to verify it is up and running.
First, you can ask minikube
about its status directly:
And if we ask kubectl
about its version, it will report both the version of the client and the version of the cluster that it is communicating with:
The first output is the version of the kubectl
client:
Immediately after, it will communicate and report the version of Kubernetes on your cluster:
And we can use kubectl
to ask for information about the cluster as well:
And see something akin to the following:
This command primarily lets you know the API server that you're communicating with is up and running. We can ask for the specific status of the key internal components using an additional command:
Kubernetes also reports and stores a number of events that you can request to see. These show what is happening within the cluster: