DEV Community

Mrinalini Sugosh (Mrina) for IBM Developer

Posted on • Updated on

Deploy an image from IBM Cloud Container Registry to Kubernetes

Welcome back to THINK Days!

A weekly blog series where I discuss and share my journey with IBM Cloud Services. Before you begin, do checkout my previous blog, Deploy a NodeJS app to IBM Cloud Container Registry. In this THINK tutorial, we will continue our knowledge of IBM Cloud Container Registry and take it a step further by deploying an app in Kubernetes using the container image we put in our registry in the previous tutorial.

Before we get started, let's think about why we need a container management system like Kubernetes. Over time, as applications are written and deployed, they tend to grow and take on new components that are deployed independently. So the one initial container image inevitably becomes many containers. At first, that growth is easy to handle (v1, v2, v3 etc...). But soon it is overwhelming (v1, v2, ..., v125, ..., v355). As your container footprint grows and evolves, a tool for managing the lifecycle of your containers becomes increasingly necessary and that's essentially where Kubernetes comes in.

Prerequistes:

  • A NodeJS App or any app that can be containerized. I have a demo app available on Github for you to follow along:
git clone https://github.com/mrinasugosh/random-cat-facts-nodejs.git
Enter fullscreen mode Exit fullscreen mode
  • kubectl CLI

If you don't already have it, I would start by installing kubectl in your terminal. The quickest way to do this for your local machine is by referring to the Kubectl CLI Docs. Here's the command for a MacOS installation:

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl"
Enter fullscreen mode Exit fullscreen mode

Now that we have our environment set up. Let's get started!

Steps to Deploy

Within the demo app, you should find a pre-filled deployment.yaml file that we will use to run the image as a Deployment. I would recommend referring to the Kubernetes docs for a detailed explanation on

kubectl apply -f deployment.yaml
Enter fullscreen mode Exit fullscreen mode

Once applied, let's list Pods until the status is "Running".

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

In order to access the application, we have to expose it to the internet and create a service of type ClusterIP via the Kubernetes Service:

kubectl expose deployment/random-cat-facts
Enter fullscreen mode Exit fullscreen mode

Open exposed, let's open a separate terminal window.
Because cluster IPs are only accesible within a cluster, we will create a proxy:

kubectl proxy
Enter fullscreen mode Exit fullscreen mode

Once the proxy is loaded, in the original terminal window, we will ping the application to get a response:

curl -L localhost:8000/api/v1/namespaces/mrinasugosh/services/random-cat-facts/proxy
Enter fullscreen mode Exit fullscreen mode

Oila! You have successfully deployed a NodeJS app to Kubernetes.

Thank you for following along this THINK Day's Tutorial and be sure to look out for my next post, where I will continue sharing my Journey with IBM Cloud Services!!!

==== Follow me on Social Media(@mrinasugosh) ====
Dev.to: @mrinasugosh
Github: @mrinasugosh
Twitter: @mrinasugosh
LinkedIn: @mrinasugosh

Top comments (0)