Excercise - 1
In this part of the lab we will deploy an application called guestbook
that has already been built and uploaded to DockerHub under the nameibmcom/guestbook:v1
. In Kubernetes, creating an application means deploying a set of pods that run containers. In this lab, you will begin with the most simple scenario of creating a deployment with a single pod using the kubectl
cli.
Create the application and service
Create the
guestbook
application deployment:This action will take a bit of time. To check the status of the running application, you can use:
You should see output similar to the following:
Eventually, the status should show up as
Running
.The end result of the run command is not just the pod containing our application containers, but a Deployment resource that manages the lifecycle of those pods.
Once the status reads
Running
, we need to expose that deployment as a Service so that it can be accessed. By specifying a service type ofNodePort
, the service will also be mapped to a high-numbered port on each cluster node. Theguestbook
application listens on port 3000, so this is also specified in the command. Run:To find the port used on that worker node, examine your new service:
The output shows that the
<nodeport>
is30805
. The service will take incoming connections to the high numbered port,30805
and forward to port3000
to the container inside the pod. For a service of type NodePort, a port in the range 30000-32767 is automatically chosen, and could be different for you.guestbook
is now running on your cluster, and exposed to the internet. We need to find out where it is accessible. The worker nodes running in the container service get external IP addresses. Run$ ibmcloud cs workers <name-of-cluster>
, and note the public IP listed on the<public-IP>
line.We can see that our
<public-IP>
is184.172.252.167
.Now that you have both the address and the port, you can now access the application in the web browser at
<public-IP>:<nodeport>
. In the example case this is184.172.252.167:30805
. Enter in a browser tab your IP address and NodePort for your deployment. Try out the guestbook by putting in a few entries. Keep this browser tab handy as you can use it in the next exercise as well.
Congratulations, you've now deployed an application to Kubernetes!
Understanding what happened
At its core, you can think of Kubernetes as being a highly-available database and a collection of watchers and controllers. Kubernetes objects and their required metadata, such as a name and their desired state, are stored in this database and the watchers and controllers act to ensure that the configuration of actual resources in the cluster matches the state stored in the database.
Last updated
Was this helpful?