Run a simple Hello World demo application in Minikube, and see whether it is working as expected.
- [Instructor] Welcome back. In the last section we set up all the requirements that we needed to get Kubernetes running locally, namely kubectl and Minikube. In this section, we're going to actually run our first hello world, so we want to do a couple of things in this section. We want to start up Minikube for the first time, we want to set up our first Kubernetes helloworld application. We want to run the application in the Minikube environment and finally expose the application via load balancer and actually see it running. First off, let's start up Minikube.
This can be accomplished by running the command minikube start. As you can tell, we are starting up a Kubernetes 1.8 cluster and the first step is to download the Minikube ISO. One thing you want to note here is you want VirtualBox to be running behind the scenes. On the Mac VirtualBox behind scenes by default, however, maybe on Windows or Linux, you might want to start that. Once this command completes, we have a local Kubernetes environment set up for us via VirtualBox.
If you want to take a look at that, type virtualbox and you'll notice that you have minikube that's up and running. We can verify that Minikube and VirtualBox are talking to each other by doing a kubectl get nodes command. This command returns a name, status, roles, age and version number. In this case we see the name is minikube and it's age of 31 seconds, which means we just created it.
Also, we have version 1.8, which represents the Kubernetes version that we just installed. Your version number might be different here, however things should still function as expected. At this point in time we know we have minikube running and everything that we need to get the Kubernetes environment up and running is available. So the next step for us to do is actually run a helloworld. So let's do that. We'll run one of the most common hello world applications out there. To do this, we're going to type kubctl run.
We're going to call this hw for our actual deployment. I'm going to pull an image called karthequian/helloworld and the image runs on port 80 so we're going to reference that. This command starts up a deployment called hw, so let's take a look. We can do this by doing a kubectl, get deployments. This returns our deployment with a desired state, current state, up to date and available of one, because we're running a single pod and it's been online for eight seconds.
We can also take a look at the replica sets by running kubectl get rs. Our replica set is named similar to deployment with hw and then post fixed with a GUID. As we can see, it has a desired state, current state, ready state of one and has been online for 32 seconds. Next up, let's take a look at our pods. To do this we do a kubectl get pods. And we have pod for our helloworld deployment that's been running for a minute.
The status of this is in a running state and we also see that the restarts of it have been zero, which is a good thing. So it looks like our deployment is online at this point in time. Next up we need to have a service for this deployment. So I'm going to clear my screen. The next thing we want to do is expose this as a service. To do this in Minikube, we want to use the kubectl expose deployment command. So let's check it out. kubectl expose deployment.
Then we need the deployment name, which in this case is hw. And we want to expose this as a type NodePort. NodePort, where node and port are capitalized. We hit enter. And this says that the service hw was exposed. So let's take a look at our service, get services. As you can notice we have a service of name hw, it's of type NodePort and it's exposed on port 32611 and it's been online for six seconds.
To actually see this application up and running, there's one last thing we need to do. We need to tell Minikube to actually pull this up in the browser. So in order to do that, we type minikube service and give it the service name, which is hw in this case. This command will bring up your web browser on port 32611 and show our helloworld application up and running. As we can see, this is a Minikube IP, 192.168.99.100 running on port 32611 and this is our simple helloworld up and running.
When we reload this page multiple times, we have a little counter on the bottom saying visit six, visit seven, eight, nine, 10, etc., whenever I refresh this page. So going back to our command prompt, we notice that our port is 32611, which matches the same port as we see on the web browser. And there you have it, that's your simple helloworld running in Kubernetes that you can also see on your web browser running via Minikube.
- What is containerization?
- Kubernetes features
- Clusters, nodes, and pods
- Deployments, jobs, and services
- Getting an application up and running
- Working with labels
- Handling application upgrades
- Dealing with configuration data
- Running jobs
- Production deployments
- Monitoring and logging
- Security in Kubernetes
Skill Level Beginner
Q: This course was updated on 06/14/2018. What changed?
A: The following topic was updated: breaking down the Hello World application.