As you can see on its web page, Kubernetes (k8s) is an open-source system for automating deployment, scaling, and management of containerized applications.
Kubernetes runs anywhere Linux does: your laptop, globally distributes data centers, major cloud providers, and so on. Stating from 5th June 2018 AWS EKS is generally available. K8S also runs on Google Cloud Platform (GCP) through its Google Container Engine (GKE).
If you want K8S in your workstation, the solution is Minikube. Minikube allows you to run the actual K8S code locally on your machine, avoiding the complexity, expense and slower response of a remote cluster; it is well supported for development and testing; it is not a prodution technology and cannot relied upon for production workloads.
Basic concepts about Kubernetes
- Kubernetes deployments are the high-level construct that define an application
- Pods are instances of a container in a deployment
- Services are endpoints that export ports to the outside world
Kubernetes “deployments” are the high-level construct that define an application
Installing kubectl
Kubectl is the Kubernetes command line tools. In order to install it, you must follow this page.
If you are on Ubuntu or one of other Linux distributions that support snap package manager, kubectl is available as a snap application.
[~]$ sudo snap install kubectl --classic
[sudo] password for lostinsoftware:
kubectl 1.13.1 from Canonical✓ installed
In order to verify your installation, execute
[~]$ kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.1", GitCommit:"eec55b9ba98609a46fee712359c7b5b365bdd920", GitTreeState:"clean", BuildDate:"2018-12-13T10:39:04Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?
Do not be alarmed at the error above. This is just because we have not set up a Kubernetes instance.
You can also install _kubectl_ using _curl_
[~]$ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
[~]$ chmod +x ./kubectl
[~]$ sudo mv ./kubectl /usr/local/bin/kubectl
[~]$ kubectl version
Installing Minikube
First of all, you need to have a hypervisor installed; you can follow the instructions to, for example, install VirtualBox at this page (for Linux). Your machine must have activated VT-X/AMD-v in BIOS.
We are going to follow instructions for Linux of this page. Again, we can make the installation using curl.
[~]$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.32.0/minikube-linux-amd64 && chmod +x minikube && sudo cp minikube /usr/local/bin/ && rm minikube
The result is
% | Total | % | Received | % | Xferd | Average Dload | Speed Upload | Time Total | Time Spent | Time Left | Current Speed |
---|---|---|---|---|---|---|---|---|---|---|---|
100 | 37.3M | 100 | 37.3M | 0 | 0 | 22.7M | 0 | 0:00:01 | 0:00:01 | --:--:-- | 22.7M |
[sudo] password for lostinsoftware:
rm: remove regular file 'minikube'? y
Let's start playing with minikube just using simple commands.
- Start minikube: minikube start
- Deploy a sample: kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080
- Expose this deployment to an external network: kubectl expose deployment hello-minikube --type=NodePort
- List the “pods” of this deployment: kubectl get pod
- Access the sample service: curl $(minikube service hello-minikube --url)
- Delete the deployment: kubectl delete deployment hello-minikube
- Stop minikube: minikube stop
Note for Windows:
When you start minikube the first time, you must be on the drive the Users directory is located on (usually on disk C:). If you are on disk D:, you will get an error similar to:
Error creating host: Error creating machine: The system cannot find the path specified
This error is due to the fact that command cd /Users fails if you are not on disk where /Users is.
An example of starting minikube in Windows is:
C:\\Users\\lostinsoftware>minikube start
Starting local Kubernetes v1.12.4 cluster...
Starting VM...
Downloading Minikube ISO
178.88 MB / 178.88 MB \[============================================\] 100.00% 0s
Getting VM IP address...
Moving files into cluster...
Downloading kubeadm v1.12.4
Downloading kubelet v1.12.4
Finished Downloading kubeadm v1.12.4
Finished Downloading kubelet v1.12.4
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Stopping extra container runtimes...
Starting cluster components...
Verifying kubelet health ...
Verifying apiserver health ...Kubectl is now configured to use the cluster.
Loading cached images from config file.
Everything looks great. Please enjoy minikube!
Results of the rest of commands are:
C:\\Users\\lostinsoftware>kubectl run hello-minikube --image=gcr.io/google\_containers/echoserver:1.4 --port=8080
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/hello-minikube created
C:\\Users\\lostinsoftware>kubectl expose deployment hello-minikube --type=NodePort
service/hello-minikube exposed
C:\\Users\\lostinsoftware>kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-minikube-6bfd75bc56-r8lct 1/1 Running 0 3m16s
C:\\Users\\lostinsoftware>minikube service hello-minikube --url
http://192.168.99.100:30524
C:\\Users\\lostinsoftware>curl http://192.168.99.100:30524
CLIENT VALUES:
client\_address=172.17.0.1
command=GET
real path=/
query=nil
request\_version=1.1
request\_uri=http://192.168.99.100:8080/
SERVER VALUES:
server\_version=nginx: 1.10.0 - lua: 10001
HEADERS RECEIVED:
accept=\*/\*
host=192.168.99.100:30524
user-agent=curl/7.55.1
BODY:
-no body in request-
C:\\Users\\lostinsoftware>kubectl delete deployment hello-minikube
deployment.extensions "hello-minikube" deleted
C:\\Users\\lostinsoftware>minikube stop
Stopping local Kubernetes cluster...
Machine stopped.