Container Native Application Development Setup with Kubernetes

Recently I have been involved in analysis and setup of container native application development setup using Kubernetes(k8s). Below are the steps I have done for the same-

Requirements
1. A Developer with access to his/her GitHub account
Developer develops an app and pushes the code to GitHub (a distributed version source code control utility)

2. Jenkins setup
Jenkins setup is required for DevOps viz. creating CI/CD pipeline/ Web Hooks. For current environment, Jenkins server is running on Google Cloud platform.

3. Dockerhub account
A valid dockerhub account is required for container image registery.

4. A Kubernetes(k8s) Cluster (GKE)
A k8s cluster is required for running the containers /container orchestration, scaling and overall container lifecycle management. I have used Google Kubernetes Engine (GKE) @ Google Cloud. It contains 1 load balancer and 3 nodes.


Conditions

K8s cluster, Jenkins, GitHub should be on the same network (if privately setup) as CI/CD is configured in Jenkins needs to talk with k8s cluster and GitHub and vice versa.

Below is the architectural diagram of current implementation-


Before we proceed, we need certain configurations setup-
Jenkins & GitHub Setup
  • Under GitHub project, we need to configure a webhook URL of Jenkins instance. Make sure the URL should be correct (necessary SSL related information should be correct)
  • Now GitHub is able to talk to Jenkins.
  • GitHub project should have Docker file in project root directory.
  • Now Jenkins needs to talk to GitHub. We have to configure the Jenkins project and enable ‘SCM-Polling), so that whenever the project changes occur in GitHub, Jenkins should know it and perform necessary build steps to automate the deployment process so-called DevOps.
  • Jenkins server should have-
    • Git installed
    • kubeconfig from k8s cluster
    • kubectl
    • Jenkins server user ‘jenkins’ should have necessary rights to execute git & kubectl commands
Setting up CI/CD (DevOps @ Jenkins)
So, our background infrastructure is ready. Now proceed for automating a project deployment at k8s cluster. So, as shown in the diagram above-
  1. Developer commits his code and pushes it to his/her GitHub account.
  2. Once the project has been deployed, GitHub gets a trigger for Jenkins.
  3. Jenkins gets a webhook trigger regarding the incident due to SCM polling.
  4. Now Jenkins needs to create a new deployment & push it to dockerhub so is build step 1 configured in Jenkins-
    • $IMAGE_NAME= “project_name:$(BUILD_NUMBER” where BUILD_NUMBER is environment variable set in Jenkins
    • docker build . –t $IMAGE_NAME\
    •  docker login –u username –p password
    • docker push $IMAGE_NAME
  5. New container image has been updated to Dockerhub 
  6. Now it comes to deploy our project to k8s cluster using build step 2 configured in Jenkins
    •  IMAGE_DEPLOY= “IMAGE_NAME:$(BUILD_NUMBER)” where BUILD_NUMBER is environment variable set in Jenkins
    • kubectl set image deployment/project_name project_name=$IMAGE_DEPLOY
So the new deployment has been rolled out and the same can be checked out with running project URL (assuming the deployment exposed type Load Balancer ). We can use kubectl command to get the IP address and port detail of an exposed service ‘validate-cc’

kubectl describe services validate-cc

This should produce output like this:

Name:                        validate-cc
Namespace:               default
Labels:                       <none>
Annotations:               <none>
Selector:                    app=example
Type:                         LoadBalancer
IP:                             10.67.252.103
LoadBalancer Ingress:123.45.678.9
Port:                          <unnamed> 80/TCP
NodePort:                  <unnamed> 32445/TCP
Endpoints:                  10.64.0.4:80,10.64.1.5:80,10.64.2.4:80
Session Affinity:         None
Events:                      <none>



So the application URL would be http://123.45.678.9:32445

Reference: https://www.youtube.com/watch?v=288rTpd1SDE





Comments

Popular posts from this blog

Oracle SOA Suite- Implementing Email Notification

Oracle SOA Suite 12c- PKIX path building failed & unable to find valid certification path to requested target

Migration of Oracle SOA Suite Composite from 11g to 12c