KUBERNETES: DEPLOYING A CONTAINERIZED MICROSERVICE

Sonu Kumar
3 min readApr 13, 2020

--

Background

I have started learning Kubernetes during Lock-down after wrapping up my head around Docker, Container & Docker-Compose file. It was difficult to understand this exciting technology. I was trying to too hard by looking at different articles and blog posts and was trying to accomplish all at once.

Its only then, that I embarked on a quest to make sure not only that I learn the concepts of Kubernetes myself, I do it in a way that makes it easier for my colleagues to understand and learn it faster than I did.

Prerequisites :

. Docker Desktop (For windows)

.Net core framework ( we are using VS 2019 )

  • Kubernetes cluster running somewhere. (Doesn’t matter if it’s minikube on your local machine or with a Cloud Provider like Google Kubernetes Engine (GKE)/ Amazon Elastic Kubernetes Service (EKS)/ Azure Container Service (AKS)(/ etc.) — I’ll be using K8s (shorthand for Kubernetes) to run a Container in them.
  • Working Docker Image of your application in an image repository somewhere. — I’ll be using an image on local machine.

Step 1: Create a deployment file:

i have already created docker image & container on my machine as below :

Therefore, i am using service1api image in deployment.yaml file as below :

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: testmicroserviceapi-deployment
spec:
selector:
matchLabels:
app: serviceapi
replicas: 2 # tells deployment to run 2 pods matching the template
template:
metadata:
labels:
app: serviceapi
spec:
containers:
— name: 1stcontainer
imagePullPolicy: IfNotPresent
image: service1api
ports:
— containerPort: 80

Step 2: Execute deployment file:

Navigate to that directory where deployment.yaml file exists and execute below command:

Step 3: Check created Pods:

Step 4: Expose the Pod using the NodePort service:

Step 5: Identify port on the node that is forwarded to the Pod:

Step 6: Test in browser :

We can see above that NodePort 30196 is exposed to test deployed service on kubernetes cluster so Open the browser and enter http://localhost:30196/api/Greeting

We can check deployed service on kubernetes dashboard as well below :

Hence our job is done !!!

Conclusion

In previous article, We have looked at how to package our applications into images via docker. In this section, we have looked into kubernetes deployments. We have looked at how to deployed docker’s containerize image to the cluster via the command-line and yaml configuration.

Has this article been useful to you? please share extensively, we also welcome feedback on content you would like us to cover .

--

--

Sonu Kumar
Sonu Kumar

Written by Sonu Kumar

Software Consultant interested in Microservices / Serverless computing, Middleware / SOA, Event Driven Architecture & Machine Learning.

No responses yet