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
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
So, our background infrastructure is ready. Now proceed for automating a project deployment at k8s cluster. So, as shown in the diagram above-
This should produce output like this:
Name: validate-cc
So the application URL would be http://123.45.678.9:32445
Reference: https://www.youtube.com/watch?v=288rTpd1SDE
- 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)
- Developer commits his code and pushes it to his/her GitHub account.
- Once the project has been deployed, GitHub gets a trigger for Jenkins.
- Jenkins gets a webhook trigger regarding the incident due to SCM polling.
- 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
- New container image has been updated to Dockerhub
- 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
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
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>
Reference: https://www.youtube.com/watch?v=288rTpd1SDE
Comments
Post a Comment