Microservice deployment on Kubernetes container with NGINX Ingress controller, Docker Hub and Helm package deployer

This blog will cover these topics:

  • Deployment of SpringBoot (Java) application on container using Kubernetes TKGI cluster
  • Run Docker Hub image on VMware TKGI cluster
  • Install and configure Helm Kubernetes package Installer
  • Install and configure NGINX Ingress controller
  • Expose micro-service as ClusterIP ingress REST API resource
  • Test and verify Microservice REST API

Prerequisite:

  • Step 1 : Create a Springboot microservice. Refer this blog series
  • Step 2 : Please follow my blog series -2: Build docker image. Use any of this build method –
    • Build docker image and store on Docker Hub or Harbor image registry. Refer this blog series.
    • Build docker OCI image using Tanzu Build Service (TBS) using Docker Hub. Refer this blog series.
  • Step 3 : Install Kubernetes cluster and switch to the K8s context where you want to deploy this docker image
  • Step 4: Install the TKGI CLI or Kubectl CLI

Create Kubernetes Deployment Configuration

Now, we need to create Kubernetes services and deployments which are required to deploy this sample microservice on K8s.

Please refer this source code for reference: https://github.com/rajivmca2004/catalogue-service/blob/master/catalogue-k8s-deployment.yml

Note (Optional Step) : imagePullSecrets only required to connect with Harbor registry. It’s not required in this demo, because we are going to use Docker Hub image registry. If you are using Harbor then, you need to create a K8s secret and add this in the K8s deployment yaml script.

kubectl create secret docker-registry regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>
# Now, you can add this above secret in deploy script -
imagePullSecrets: # Only required with private image repository like Harbor,jFrog etc
        - name: regcred

1. Create ClusterIP Service:

We need to create a service on “online-store” namespace and expose on port 8010 which will expose this microservice internal to K8s cluster –

apiVersion: v1
kind: Service
metadata:
  name: catalogue-service
  namespace: onlinestore-demo
spec:
  ports:
  - port: 8010
    protocol: TCP
    targetPort: 8010
  selector:
    app: catalogue-service-app
  sessionAffinity: None
  type: ClusterIP #internal IPs withing K8s cluster,exposed to external IP with Ingress Load balancer service
status:
  loadBalancer: {}

2. Create Deployment

Now, create a deployment which will pull image of this micro-service from Docker-Hub image registry from login: itsrajivsrivastava/catalogue-service, which will create 3 replicas/containers of PODs and one container per POD-

apiVersion: apps/v1
kind: Deployment
metadata:
  name: catalogue-service-app-deployment
  namespace: onlinestore-demo
spec:
  selector:
    matchLabels:
      app: catalogue-service-app
  replicas: 3 # tells deployment to run N pods matching the template
  template: # create pods using pod definition in this template
    metadata:
      labels:
        app: catalogue-service-app
    spec:
      containers:
      - name: catalogue-service-app
        image: itsrajivsrivastava/catalogue-service
        ports:
        - containerPort: 8010
          name: server

Install Helm (Optional) for easy deployment on K8s Clusters

https://helm.sh/docs/intro/quickstart/

$ brew install helm

Kubernetes Ingress-nginx Controller Setup with Helm Simplified…Create and Configure Ingress

Read about Ingress- https://kubernetes.io/docs/concepts/services-networking/ingress/

3. Install Ingress-nginx Controller using Helm

Refer this doc for more info:

$ helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
$ helm install my-release ingress-nginx/ingress-nginx
#These k8s objects will be created after installing Nginx Ingress Controller- https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-0.32.0/deploy/static/provider/cloud/deploy.yaml

4. Create an Ingress

Note: You need to create a DNS entry or use direct IP address of Ingress resource for host name.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: catalogue-service-app-ingress
  namespace: default
spec:
  rules:
  - host: demo.my-pks.cloudification.in
    http:
      paths:
      - backend:
          serviceName: catalogue-service
          servicePort: 8010
        path: /catalogue

5. Test and verify Microservice REST API

Test Nginx Ingress resource from external system terminal/Browser:

curl -v demo.my-pks.cloudification.in/catalogue

http://demo.my-pks.cloudification.in/actuator/health

My CKAD Certification experience: Tips and tricks

I have passed CKAD (Certifies Kubernetes Application Developer) exam in June’2020! It was really a race against time! It’s a fast pace, online coding exam!
In this blog, I will share my exam experience, hope it will be helpful for you.

It’s an open book exam, however you can only browse Kubernetes official website and their related blogs. You can’t Google search and find the answers. You can copy and paste YAML based code from K8s official portal only.

Exam Prepration

I have started preparation with CKAD Udemy online course of Mumshad Mannambeth. It’s an awesome online tutorial with real lab environment, where you will be given readymade Kubernetes cluster lab KodeKloud platfrom, It’s superb! Here, you can write code in K8s yaml files and run instantly without any K8s cluster configuration. It’s also creates K8s resources for you and also validates your answers.

Other Resources:

It would be great to setup a MiniKube or Kind ( Kubernetes in Docker) K8s cluster on your laptop/computer to practice more questions. I have used these resources to practice the exam-

D-Day (Exam-Day):

It’s a tough exam where you have to read, understand, code and verify in 6 minutes. There will be 19 questions and passing marks are 67%. It’ very difficult to complete all the questions in 2 hours. These are tips I have followed to do time management:

It’s 2 hours online coding exam where a human exam proctor will keep an eye on you for this duration by looking at you thru Web Camera and your monitor screen thru screen sharing!

Tips to save time and attempt most of the questios:

  • Practice, practice, practice so that your finger remembers popular commands and syntax!
  • Don’t try to create YAML file manually during exam! Use Kubectl imperative commands to generate yaml. Export yaml file by –dry-run -o yaml>pod.yaml and then edit this YAML file in vi editor. Once, you are confident, then save
  • They provide vim/nano. I prefer vi, it’s simple.
  • Always verify K8s objects status and logs after K8s object creating command. It will give you confidence!
  • Hit easy questions with high weight first: >10% and get back later for question with weight: 2–3% or those questions which are big and complex, and you are not sure.
  • Use exam console’s NotePad to track all your questions. Write all questions in new rows and write weightage and mark if you have completed. You can also click on a button to mark your questions which you want to return later. You can also shuffle easy and high score questions on the top and low marks and complex questions at the bottom. e.g: Here d means “done”
    • 1-13-d
    • 2-9-d
    • 3-7-p
  • Save important bookmarks and use as boomark tool bar to save time in searching bookmark links. You can download this bookmark which I have used from Github.
  • Create aliases before starting the exam and save it on Notebook which will be provided on exam console. You can’t use your personal Notepad or any copy-paste from your local computer to exam console browser’s windows. I have just used these aliases:
$ alias k=kubectl
$ alias kx="kubectl config current-context"
$ alias kn="kubectl config use-context"
$ alias kall="kubectl get all"
$ alias kc="kubectl create -f"

All the best!

About Author – Rajiv Srivastava

Rajiv Srivastava is the founder of https://cloudificationzone.com/, which is a cloud native modern application blog site for cloud native developers, architects and enthusiastic who are interested in end to end design and development of cloud based modern applications  by using build, run, monitor, secure and manage approach with modern technologies.

He is working as a Cloud Native Solution Architect with a leading product development company VMware, a blogger, author, a passionate technologist, Java/Spring/Kubernetes developer and architect.

He has 15+ years of work experience in development and design solution architecture. He has expertise in modern application, cloud migration, Kubernetes platform, event sourcing architecture, NodeJS, Tanzu, cloud, docker, API Gateway, Service Mesh, CI/CD, containerization, GCP, AWS, open-sources, distributed, serverless, Microservices, REST APIs, Spring, Caching, Kafka, RabbitMQ, SQL/No-SQL, MongoDB, ElasticSearch, enterprise integration, unit/integration and performance testing, code profiling etc.

Location: He is based in Gurgaon (New Delhi NCR) India

Certifications:

  1. He is  Sun Certified Java Professional (SCJP)
  2. Certified Kubernetes Application developer (CKAD).
  3. Other Certifications: ElasticSearch, Spring Cloud data Flow, ITIL, Six Sigma White, SNIA etc.

Work Experience:

He has worked with these companies from past 15+ yrs:

  • VMware (Current Company)
  • GlobalLogic
  • Wipro
  • Infogain
  • COLT
  • Sapient
  • Dell EMC

He has worked with these clients:

  • Kohls, USA
  • Apple, USA
  • Fedex, USA
  • AT&T, USA
  • Sprint Telecom, USA
  • Commercial clients etc.

Academics:

  • MCA (Masters of Computer Applications/Master of Computer Science) from Bangalore University, India in 2004
  • BCA (Bachelors of Computer Applications
  • DST (Diploma in Software Technology) from CMC Ltd.

Skill Set and hand on technical expertise:


Experience in cloud migration, app modernization, Core Java, JEE, SpringBoot (Cloud, DI/IOC, MVC, AOP,Integration, REST Web Services, Security), Kubernetes, Redis, Kafka, RabbitMQ, framework, ArgoCD, Docker, Harbor, Docker Concourse,Grafana, Prometheus, JProfiler, Cucumber, Hibernate, JMS,Tomcat, ElasicSearch, MongoDB, MySQL,ELK, EFK, Splunk.

Domain Expertise:

  • E-Commerce/Retail applications.
  • Order management (Telecom)
  • Search Engine
  • MDM
  • Storage domains
  • Technical: Cloud, No-SQL and Storage.

His Technical Social profile:

WhitePapers:

  1. https://www.hcltech.com/white-papers/digital-analytics/accelerating-application-transformation
  2. https://www.globallogic.com/gl_news/microservices-test-automation-bdd-with-cucumber-jvm

Work Profile:

# A passionate technologist, a cloud-native application solution architect and API/Microservices developer, blogger, from a rich development background of Java, Python, NodeJS, SpringBoot, REST API, Caching, messaging, No-SQL and MicroServices, Event sourcing architecture, Integration Architecture, unit , integration testing, GCP, AWS, Tanzu products, cloud architecture and open source technologies.
# Founder of cloudificationzone.com
# Overall 15+ years of software of development, designing and implementing Distributed, Cloud-native -based microservices, Client-Server and Web-based enterprise applications using Java, Microservices and open source technologies for B2B, B2C projects enterprise-grade production applications.
# 5+ years of cloud and microservice experience in AWS, GCP, OpenShift (PAAS), Cloud Foundry (PAAS).
# 6+ years of deep eCommerce experience for USA’s top 5 companies – Apple and Kohls and exposure of online shopping, cart checkout, catalog, retail orders, inventory, MDM, product launch, mobile commerce, omnichannel, wallet and promotions, fraud detection, security issues of eCommerce apps etc.
# Excel in building quick Proof Of Concepts (POC), Proof of Technology (POT).
# Cloud migration of Java enterprise application, Kubernetes on-prem, private anc public cloud (AWS,GCP) using Micro-Services architecture. CI/CD pipeline. Design new cloud applications
# Design Patterns and Methodologies: Good Understanding of MicroServices architecture, GOF patterns, Core Java/J2EE Patterns, OOPS, MVC. Agile, SDLC,TDD in multi-project implementations.

Rajiv

Step by Step: Create a SpringBoot Microservice, dockerize, run on docker and deploy on Kubernetes

This blog has simple step by step info to build, containerize and run a microservice. I have written detail separate blogs for all the following steps. This blog is just an index or reference to those blogs at one place: