Skip to content

tkanos/minikube_kubernetes_tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 

Repository files navigation

Kubernetes on Local with Minikube Tutorial

Install

You need to install in your machine :

Let's Play

Starting ...

First start minikube that will run in local kubernetes (instead have to use google cloud or AWS )

minikube start

Check that Kubernetes are running well

kubectl cluster-info

First example :

For your first example you can follow the one given by minikube itself : https://github.com/kubernetes/minikube#quickstart

Second example :

We will do more fun things that this first example. Once minikube is started you can do everything kubernetes allow (there are a lot of tutorial in internet) with some differences that we will see throught an example :

Let's begin by creating 2 replication of an nginx docker load balanced on Kubernetes.

kubectl run test-nginx --image=nginx --replicas=2 --port=80 --expose --service-overrides='{ "spec": { "type": "LoadBalancer" } }'

You can see your 2 replicas some seconds later "running" by typing

kubectl get pod

Once it's running you can see their internal IP

kubectl get services

You can't see their external IP, because it's running in a minikube To Test you can find the ip by typing :

minikube service test-nginx --url 

ngnix_screen

or if you are using linux :

curl $(minikube service test-nginx --url)

Playing with replicas

Let's delete one of our pod, and see how kubernetes behave : So get the name of one of your pods typing :

kubectl get pod

Once you have the name :

kubectl delete pod [name]

And right after you will see kubernetes creating an other container to continue having 2 replicas :

kubectl get pod

Entering in a container

check the name of your pods

kubectl get pod

Execute the following command with the name of your first pod.

kubectl exec -ti test-nginx [name] --bash

You will have the prompt commnd inside of the nginx container. Type :

cd /usr/share/nginx.html
rm index.html & echo "<html><body><h1>Hello World</h1></body></html>" > index.html
exit

reload the page

Cleaning

Don't forget to clean your room :

kubectl delete deployment test-nginx
kubectl delete service test-nginx
minikube stop

Third Example

We will try to dockerize our own code. This comes from the excellent tutorial http://kubernetes.io/docs/hellonode/, but applied to minikube

Create in a directory 2 files :

  • server.js
  • dockerfile

Edit server.js with :

const http = require('http');
const handleRequest = (request, response) => {
  console.log('Received request for URL: ' + request.url);
  response.writeHead(200);
  response.end('Hello World!');
};
const www = http.createServer(handleRequest);
www.listen(8080);

Edit the dockerfile with :

FROM node:4.5
EXPOSE 8080
COPY server.js .
CMD node server.js

Now we will build your docker file inside minikube for that on your console type :

eval $(minikube docker-env)

if you do a docker images you will see that in this console you are not anymore inside your own docker, but inside the minikube one.

So build your dockerfile :

docker build -t hellonode:v1 .

Now we will mount this image :

kubectl run test-node --image=hellonode:v1 --port=8080

you can see it deployed :

kubectl get deployments

you can see it running :

kubectl get pods

Once it is running, we will allow external traffic :

kubectl expose deployment test-node --type="LoadBalancer"

check :

kubectl get services

we can now test :

curl -i $(minikube service test-node --url)
HTTP/1.1 200 OK
Date: Fri, 9 Dec 2016 14:57:19 GMT
Connection: keep-alive
Transfer-Encoding: chunked

Hello World!

Scale

With Kubernetes it's easy to scale, we only need one command line :

kubectl scale deployment test-node --replicas=4

And in order to check :

kubectl get deployments
kubectl get pods

Links :

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published