Kubernetes is new framework by Google to manage Linux container clusters. I started playing with it today and it seems like a cool, powerful tool to manage a huge barrage of containers and to ensure that a predefined number of containers are always running. Installation and configuration on Fedora and many other distributions can be found at these Getting Started Guides. I recommend using two machines for this experiment (one physical and one VM is fine). Kubelet (or Minion) is the one where Docker containers will run, so use more powerful machine for that.
After the installation we'll see something like below when we look for minions from kube master:
.. except, (as on 25 Dec 2014) it won't run. It will give an error like this:
Turns out that a field "kind" is empty. So the kubectl won't be able to run the container. Correct this so that kubeintro looks like this:
Once the kubeintro.yaml is fixed, we can run it on the master and we'll see that a container is started on the minion. We can stop the container on the minion using
The example above doesn't do much. We need to publish the ports of the container so that we can access the webpage served by it. Modify the kubeintro.yml to tell it to publish ports like this:
If you need any help with managing kubernetes, checkout my consulting services.
After the installation we'll see something like below when we look for minions from kube master:
master# kubectl get minions
NAME LABELS
fed-minion <none>
Now we would move to Kubernetes 101 Walkthrough where we will run a container using the yaml from the Intro section.master# kubectl create -f kubeintro.yaml
the provided version "v1beta1" and kind "" cannot be mapped to a supported object
master# cat kubeintro.yaml
apiVersion: v1beta1
kind: Pod
id: www
desiredState:
replicas: 2
manifest:
version: v1beta1
id: www
containers:
- name: nginx
image: dockerfile/nginx
Optional: Now, I do not exactly know what is there inside the image "dockerfile/nginx". So I would replace it with something that I want to spawn like "adimania/flask" image. The dockerfile for my flask image can be found in Fedora-Dockerfiles repo.Once the kubeintro.yaml is fixed, we can run it on the master and we'll see that a container is started on the minion. We can stop the container on the minion using
docker stop
command and we'll see the kubernetes will start the container again.The example above doesn't do much. We need to publish the ports of the container so that we can access the webpage served by it. Modify the kubeintro.yml to tell it to publish ports like this:
master# cat kubeintro.yaml
apiVersion: v1beta1
kind: Pod
id: www
desiredState:
replicas: 2
manifest:
version: v1beta1
id: www
containers:
- name: nginx
image: dockerfile/nginx
ports:
- containerPort: 80
hostPort: 8080
Now delete the older pod named www and start a new one from the new kubeintro.yaml file.master# kubectl delete pod www
master# kubectl create -f kubeintro.yaml
We can browse via a browser to localhost:8080 and we'll see Nginx serving the default page. (If we would have used "adimania/flask" image, we would have seen "Hello from Fedora!" instead.)If you need any help with managing kubernetes, checkout my consulting services.