taste some kubernetes, start with minikube

I was not a big fan on container technology. Well, duty calls. So I would start with tutorials and Minikube on laptop.

Installation is simple. Instruction is here.

One need kubectl and minikube, both is available as pre-built binary on Mac, and can be readily downloaded via curl.
For simplicity best not to move them to /usr/local/bin as in instruction. Just put them somewhere in user PATH would do.

One more requirement is hypervisor. I would use VirtualBox for Mac (HyperKit need a bit work, while VMWare Fusion cost money).

After installation, one need to start Minikube for the first-time. minikube start would do.

However, for mainland China, one had to retrieve ISO and image from AlibabaCloud mirror. Command line would be

minikube start --iso-url 'https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.2.0.iso' --image-mirror-country cn

for current Minikube version 1.2.0. There is a GitHub with modified default ISO URL. Here the ISO URL could be found as DefaultISOURL at minikube/pkg/minikube/constants/constants.go
If there is future upgrade, remember to use latest version.

After Minikube is started, one can try with some deployment. Start a Node.js echo server (again, mainland China need to use a mirror, instead of default gcr.io).

kubectl create deployment hello-node --image=registry.cn-hangzhou.aliyuncs.com/google_containers/echoserver:1.10

It will create echo server deployment on the pod. The server can be accessed locally within the pod.

kubectl exec $POD_NAME -- curl localhost:8080

Next, one can expose it as service.

kubectl expose deployment hello-node --type=LoadBalancer --port=8080

Check status.

kubectl get all

Sample response (note the external NODE_PORT on service/hello-node, 30252).

NAME                              READY   STATUS    RESTARTS   AGE
 pod/hello-node-67c8cf8784-9t2h6   1/1     Running   0          15m
 

 

 NAME                 TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
 service/hello-node   LoadBalancer   10.104.130.7   <pending>     8080:30252/TCP   3m49s
 service/kubernetes   ClusterIP      10.96.0.1      <none>        443/TCP          5h6m
 

 

 NAME                         READY   UP-TO-DATE   AVAILABLE   AGE
 deployment.apps/hello-node   1/1     1            1           16m
 

 NAME                                    DESIRED   CURRENT   READY   AGE
 replicaset.apps/hello-node-67c8cf8784   1         1         1       15m
 

All is fine. Now it can be accessed externally.

minikube service hello-node

Above command line is just a convenience, simple

curl $(minikube ip):$NODE_PORT

would do.

Further, deployment can be scaled-up (to 2 pods).

kubectl scale deployment.apps/hello-node --replicas=2

After having enough of our echo service, one can shut it down.

kubectl delete service hello-node
kubectl delete deployment hello-node

Further, stop Minikube (to save some CPU and memory).

minikube stop
Advertisements
This entry was posted in Cloud, Computer and Internet and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s