Getting Started with Kubernetes
The first step we need to do is to start the Kubernetes cluster. To do so, we need to use the "start" command.
If the "~/.minikube/" folder does not exist, minikube will automatically download the ISO files.
The output will look like this:
Starting local Kubernetes v1.10.0 cluster... Starting VM... Downloading Minikube ISO 153.08 MB / 153.08 MB [============================================] 100.00% 0s Getting VM IP address... Moving files into cluster... Downloading kubelet v1.10.0 Downloading kubeadm v1.10.0 Finished Downloading kubeadm v1.10.0 Finished Downloading kubelet v1.10.0 Setting up certs... Connecting to cluster... Setting up kubeconfig... Starting cluster components... Kubectl is now configured to use the cluster. Loading cached images from config file.
We can verify to make sure all is good:
This will show the status and the IP address of the cluster.
minikube: Running cluster: Running kubectl: Correctly Configured: pointing to minikube-vm at 192.168.99.100
Now let's navigate to the dashboard.
Create a test deployment
Kubernetes comes with a "hello-minikube" to play and test deployment. Kubernetes' deployments manage stateless services running on your cluster (as opposed to for example StatefulSets which do manage stateful services). Their purpose is to keep a set of identical pods running and upgrade them in a controlled way – performing a rolling update by default.
Create and run the deployment
kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.10 --port=8080
The output should show "deployment.apps "hello-minikube" created". This means now the "hello-minikube" deployment is added to the dashboard. If you refresh your dashboard, you should see it.
Expose the deployment
kubectl expose deployment hello-minikube --type=NodePort
This will now expose and launch a new deployment and create the service for it.
List the pod
kubectl get pods
This will show the newly created pod:
NAME READY STATUS RESTARTS AGE hello-minikube-7c77b68cff-tvgrt 1/1 Running 0 7m
See it in action!
This newly service can be access from your Internet browser. You can find the URL to load in the "Discovery and load balancing / Services / hello-minikube" or by running this command:
minikube service hello-minikube --url
Delete the service
If a service is not required anymore, we can remove it from the cluster.
kubectl delete services hello-minikube kubectl delete deployment hello-minikube kubectl delete pods hello-minikube-7c77b68cff-tvgrt # you can get this name using the "kubectl get pods" command