TranslateProject/sources/tech/20170823 Using Kubernetes for Local Development — Minikube.md
2017-08-27 10:53:52 +08:00

7.5 KiB
Raw Blame History

Using Kubernetes for Local DevelopmentMinikube

If you ops team are using Docker and Kubernetes, it is recommended to adopt the same or similar technologies in development. This will reduce the number of incompatibility and portability problems and makes everyone consider the application container a common responsibility of both Dev and Ops teams.

This blog post introduces the usage of Kubernetes in development mode and it is inspired from a screencast that you can find in Painless Docker Course.

]1

Minikube is a tool that makes developers life easy by allowing them to use and run a Kubernetes cluster in a local machine.

In this blog post, for the examples that I tested, I am using Linux Mint 18, but it doesnt change nothing apart the installation part.

cat /etc/lsb-release 
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=18.1
DISTRIB_CODENAME=serena
DISTRIB_DESCRIPTION=”Linux Mint 18.1 Serena”

Prerequisites

In order to work with Minkube, we should have Kubectl and Minikube installed + some virtualization drivers.

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.21.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.7.0/bin/windows/amd64/kubectl.exe

Add the binary to your PATH (This article explains how to modify the PATH)

Download the minikube-windows-amd64.exe file, rename it to minikube.exeand add it to your path.

Find the last release here.

  • For Linux, install VirtualBox or KVM then Kubectl and Minkube
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
curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.21.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

Using Minikube

Lets start by creating an image from this Dockerfile:

FROM busybox
ADD index.html /www/index.html
EXPOSE 8000
CMD httpd -p 8000 -h /www; tail -f /dev/null

Add something youd like to see in the index.html page.

Build the image:

docker build -t eon01/hello-world-web-server .

Lets run the container to test it:

docker run -d --name webserver -p 8000:8000 eon01/hello-world-web-server

This is the output of docker ps:

docker ps

CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                    NAMES
2ad8d688d812        eon01/hello-world-web-server   "/bin/sh -c 'httpd..."   3 seconds ago       Up 2 seconds        0.0.0.0:8000->8000/tcp   webserver

Lets commit the image and upload it to the public Docker Hub. You can use your own private registry:

docker commit webserver
docker push eon01/hello-world-web-server

Remove the container since we will use it with Minikube

docker rm -f webserver

Time to start Minikube:

minkube start

Check the status:

minikube status

We are running a single node:

kubectl get node

Run the webserver:

kubectl run webserver --image=eon01/hello-world-web-server --port=8000

A webserver should have its port exposed:

kubectl expose deployment webserver --type=NodePort

In order to get the service url type:

minikube service webserver --url

We can see the content of the web page using :

curl $(minikube service webserver --url)

To show a summary of the running cluster run:

kubectl cluster-info

For more details:

kubectl cluster-info dump

We can also list the pods using:

kubectl get pods

And to access to the dashboard use:

minikube dashboard

If you would like to access the frontend of the web application type:

kubectl proxy

If we want to execute a command inside the container, get the pod id using:

kubetctl get pods

Then use it like :

kubectl exec webserver-2022867364-0v1p9 -it -- /bin/sh

To finish, delete all deployments:

kubectl delete deployments --all

Delete all pods:

kubectl delete pods --all

And stop Minikube

minikube stop

I hope you enjoyed this introduction.

Connect Deeper

If you resonated with this article, you can find more interesting contents in Painless Docker Course.

We, Eralabs, will be happy to help you on your Docker and Cloud Computing projects, contact us and we will be happy to hear about your projects.

Please subscribe to DevOpsLinks : An Online Community Of Thousands Of IT Experts & DevOps Enthusiast From All Over The World.

You may be also interested in joining our newsletter Shipped, a newsletter focused on containers, orchestration and serverless technologies.

You can find me on TwitterClarity or my website and you can also check my books: SaltStack For DevOps.

Dont forget to join my last project Jobs For DevOps !

If you liked this post, please recommend it and share it with your followers.


作者简介:

Aymen El Amri Cloud & Software Architect, Entrepreneur, Author, CEO www.eralabs.io, Founder www.devopslinks.com, Personal Page : www.aymenelamri.com


via: https://medium.com/devopslinks/using-kubernetes-minikube-for-local-development-c37c6e56e3db

作者:Aymen El Amri 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出