Run A Container In Kubernetes Cluster Using Devtron’s CI/CD Tool

by Nivesh Goyal
September 4, 2020
Run A Container in Kubernetes Cluster Using Devtron's CI/CD Tools

In the previous blog, we discussed how to run a cron job inside a docker container. Here, we are going to discuss how to spin up a Dockerfile in the Kubernetes cluster using Devtron’s CI/CD tool.

Why Devtron’s CI/CD tool?

  • To make your Kubernetes deployments hassle-free and to provide monitoring and logging of all your applications a one-stop solution, Devtron CI/CD tool can be your answer.

Pre-requisite: 

  • Get the Devtron tool configured for your Kubernetes cluster.
  • Push your code to GitHub public repository.

Steps to deploy containers in a Kubernetes cluster using Devtron’s tool:

1> Login to Devtron’s CI/CD tool:

This is how Devtron landing page looks like. It displays all your applications running in the Kubernetes cluster along with the status of your application and a few other details. More details can be viewed by clicking on any of the applications from here. 

2> Create a dummy application:

Now on the top right corner, there is an “Add New App” option, to add/deploy a new application in the k8s cluster, click on it. A window will appear as shown below. Here, provide  information like your application Name, Project, Template, and click on “Create App” to create your application.

3> Provide Code repository details:

You can see your application name on the landing page. Now click on the application to configure it. 

You will be directed to the App Details page. As of now, nothing is configured in your application. To configure it, click on the “Configure” option on the top right corner. 

On the configuration page, you can see multiple options like git material, Docker Build Config Deployment Template, etc. By default, you will be directed to the “Git Materials” option. Here you have to provide your code repository details.

4> Provide a Docker file path and docker image repository details:

Now click on “Save” and press the “Next” button. Now you are in “Docker build config”. Under this section, you have to provide Docker file details, such as the path of your docker file and the name of the Dockerfile. Also provide details about the Docker image repository, the place where you want to store your docker image. Now click on “Save configuration” and hit the “Next” button.

5> Provide deployment configs:

Now you are in the “Deployment Template”  Section. Here you will define your deployment configuration.

You can find a default Yaml file here, you only have to change a few values like container name, port, replica count, etc.(*Make changes as per your requirement).

Once done, click on “Save” and hit the “Next” button. Below is the sample Yaml file. 

ContainerPort:
    - name: cronjob-app
      port: 80
      servicePort: 80
EnvVariables: []
GracePeriod: 30
LivenessProbe:
    Path: ""
    command: []
    failureThreshold: 3
    httpHeader:
        name: ""
        value: ""
    initialDelaySeconds: 20
    periodSeconds: 10
    port: 8080
    scheme: ""
    successThreshold: 1
    tcp: false
    timeoutSeconds: 5
MaxSurge: 1
MaxUnavailable: 0
MinReadySeconds: 60
ReadinessProbe:
    Path: ""
    command: []
    failureThreshold: 3
    httpHeader:
        name: ""
        value: ""
    initialDelaySeconds: 20
    periodSeconds: 10
    port: 8080
    scheme: ""
    successThreshold: 1
    tcp: false
    timeoutSeconds: 5
Spec:
    Affinity:
        Key: null
        Values: nodes
        key: ""
args:
    enabled: false
    value:
        - /bin/sh
        - -c
        - touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
autoscaling:
    MaxReplicas: 2
    MinReplicas: 1
    TargetCPUUtilizationPercentage: 90
    TargetMemoryUtilizationPercentage: 80
    enabled: false
command:
    enabled: false
    value: []
containers: []
dbMigrationConfig:
    enabled: false
envoyproxy:
    configMapName: ""
    image: envoyproxy/envoy:v1.14.1
image:
    pullPolicy: IfNotPresent
ingress:
    annotations:
        kubernetes.io/ingress.class: nginx
        nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
        nginx.ingress.kubernetes.io/rewrite-target: /$2
        nginx.ingress.kubernetes.io/ssl-redirect: "false"
    enabled: enabled
    host: ""
    path: /pro-test(/|$)(.*)
    tls: []
ingressInternal:
    annotations: {}
    enabled: false
    host: ""
    path: ""
    tls: []
initContainers: []
pauseForSecondsBeforeSwitchActive: 30
prometheus:
    release: monitoring
rawYaml: []
replicaCount: 1
resources:
    limits:
        cpu: "0.02"
        memory: 20Mi
    requests:
        cpu: "0.01"
        memory: 10Mi
secret:
    data: {}
    enabled: false
server:
    deployment:
        image: ""
        image_tag: 1-95af053
service:
    annotations: {}
    type: ClusterIP
servicemonitor:
    enabled: false
volumeMounts: []
volumes: []
waitForSecondsBeforeScalingDown: 3

6> Create CI pipeline:

Now you are on the 4th Section “Workflow Editor”. Here you can configure your CI/CD pipeline. Click on the “Create Workflow” and give a name to your workflow and click on “Save”

Now click on “Add CI Pipeline”, select your option. In my case, I have selected “Continuous Integration”. A window will be opened for you, fill in the necessary information like CI Pipeline name, Branch, and select CI option from Automatic or Manual as per your flexibility. Click on “Create Pipeline” and your CI pipeline is created.

7> Create a CD pipeline:

You can see a screen like below, now click on the “+” button and select “Deploy to Environment” option to create your CD pipeline.

Again you have to fill in the necessary information like CD pipeline name, Select Environment, and select CD option from Automatic and Manual. Click on “Create Pipeline”. Your CD Pipeline is created.

8> Trigger your deployment:

Now click on “Go to Triggers” on the top right corner of the page. You will be redirected to the CI Trigger page. Here, click on “Select Material” under the “Build” section, select your commit ID and click on “Start Build”. Check the below screenshot for more details.

You can also view logs of your build under Build History Tab. Once your build is succeeded, click on “Select Image” under the “Deploy” section, select your newly created image and click on “Deploy

9> Monitor your Application status and logs:

You can monitor your Deployment under Deployment History Tab. Once your image is deployed and the application comes in healthy status, go to “App Details”.

Here you can see application details like the status of the application, number of pods running along with the status of these pods. You can also view detailed logs of these pods by clicking on any of the pods. In my case, I can see my cron job logs that are running every minute.

That’s all about the deployment of cron job inside Kubernetes pods using devtron CI/CD tool.

Subscribe for DevOps updates

Invalid email address
We promise not to spam you. You can unsubscribe at any time.
Recent posts