Continuous Integration and Continuous Deployment (CI/CD) are important in modern software development, automating code testing and deployment. Integrating with Kubernetes offers a robust and scalable approach to managing these processes efficiently. This blog post aims to guide you through this integration in a clear, direct, and uncomplicated manner. and Kubernetes is a continuous integration tool that automates building, testing, and deployment processes. Kubernetes, in contrast, is an open-source platform for managing containerized applications across multiple hosts, providing essential mechanisms for the deployment, maintenance, and scaling of applications.

Why Integrate with Kubernetes?

The integration of with Kubernetes brings together the strengths of both platforms:'s efficient automation capabilities and Kubernetes' advanced container orchestration. This combination streamlines your development workflow, enhancing its efficiency and scalability.

Steps for Integration

1. Setting Up the Environment

  • Install Kubernetes: Make sure you have a Kubernetes cluster ready.
  • Set Up Create a account and connect it with your version control system (like GitHub).

2. Configuring a sample application with DigitalOcean Kubernetes

version: "1"
  - name: sample-expressjs-pipeline-do-k8s-cdktf:0.2.5
    description: Build and Publish an image in a DigitalOcean Container Registry
        - DEBIAN_FRONTEND=noninteractive
        - STACK_TYPE=do-k8s-cdktf
        - ORG=cto-ai
        - GH_ORG=workflows-sh
        - REPO=sample-expressjs-do-k8s-cdktf
        - BIN_LOCATION=/tmp/tools
        - GITHUB_TOKEN
        - DO_TOKEN
      - "github:workflows-sh/sample-expressjs-do-k8s-cdktf:pull_request.opened"
      - "github:workflows-sh/sample-expressjs-do-k8s-cdktf:pull_request.synchronize"
      - "github:workflows-sh/sample-expressjs-do-k8s-cdktf:pull_request.merged"
      - name: sample-expressjs-build-do-k8s-cdktf
        description: Build step for sample-expressjs-do-k8s-cdktf
          - git
          - unzip
          - wget
          - tar
          - mkdir -p $BIN_LOCATION
          - export PATH=$PATH:$BIN_LOCATION
          - ls -asl $BIN_LOCATION
          - DOCTL_DL_URL='' # Update to latest doctl binary here by providing URL
          - wget $DOCTL_DL_URL -O doctl.tar.gz
          - tar xf doctl.tar.gz -C $BIN_LOCATION
          - doctl version
          - git version
          - git clone https://oauth2:[email protected]/$GH_ORG/$REPO
          - cd $REPO && ls -asl
          - git fetch -a && git checkout "${REF}"
          - doctl auth init -t $DO_TOKEN
          - doctl registry login
          - CLEAN_REF=$(echo "${REF}" | sed 's/[^a-zA-Z0-9]/-/g' )
          - docker build -f Dockerfile -t one-img-to-rule-them-all:latest .
          - docker tag one-img-to-rule-them-all:latest$ORG/$REPO:$CLEAN_REF
          - docker push$ORG/$REPO:$CLEAN_REF
  - name: sample-expressjs-service-do-k8s-cdktf:0.1.6
    description: Preview of image built by the pipeline
    run: node /ops/index.js
    port: [ '8080:8080' ]
    sdk: off
    domain: ""
        - PORT=8080
      - "github:workflows-sh/sample-expressjs-do-k8s-cdktf:pull_request.opened"
      - "github:workflows-sh/sample-expressjs-do-k8s-cdktf:pull_request.synchronize"
      - "github:workflows-sh/sample-expressjs-do-k8s-cdktf:pull_request.merged"
      - build
      - publish
      - start
  1. Version: Indicates the version of the pipeline configuration.

Pipelines: Defines a sequence of processes for building, testing, and deploying code.

  • Name and Description: This pipeline is named sample-expressjs-pipeline-do-k8s-cdktf:0.2.5 and is described as a process for building and publishing an image to DigitalOcean's Container Registry.

Environment Variables:

  • Static: Defines constant environment variables like DEBIAN_FRONTEND, STACK_TYPE, organization names, repository name, and binary location.
  • Secrets: Specifies secret tokens (GITHUB_TOKEN and DO_TOKEN) used for authentication.
  • Events: Triggers the pipeline on specific GitHub events like opening, synchronizing, or merging a pull request in the specified repository.


  • Defines a job (sample-expressjs-build-do-k8s-cdktf) for building the application.
  • Installs necessary packages (git, unzip, wget, tar).
  • Executes a series of steps to set up the environment, download and install the DigitalOcean CLI tool (doctl), clone the GitHub repository, authenticate with DigitalOcean, build a Docker image, tag it, and then push it to DigitalOcean's Container Registry.

Services: Defines services that run as part of the pipeline.

  • Service Configuration:
  • Names the service sample-expressjs-service-do-k8s-cdktf:0.1.6.
  • Describes it as a preview service for the built image.
  • Specifies the runtime environment (node /ops/index.js).
  • Sets the port and other environment variables.
  • Events and Trigger: The service is triggered on the same GitHub events as the pipeline and is linked to the build, publish, and start actions.
  • Create a Configuration File: Add a ops.yml file in your project repository to outline the automation process.

3. Defining Workflows and Jobs

  • Define Jobs: Specify jobs like building, testing, and deploying in the ops.yml.
version: "1"
  - name: kubernetes-integration-pipeline
      - name: build-and-deploy
          - echo "Building and Deploying"
          - docker build -t your-image .
          - docker push your-image
          - kubectl set image deployment/your-deployment your-container=your-image

  • Create Workflows: Design workflows, which are sequences of jobs executed in a specific order, to reflect your CI/CD pipeline.

4. Deployment to Kubernetes

  • Dockerize Your Application: Write a Dockerfile to containerize your application.
FROM node:14
COPY . .
RUN npm install
CMD ["node", "app.js"]

  • Deploy Using In your ops.yml, include steps for building the Docker image, pushing it to a container registry, and then deploying this image to your Kubernetes cluster.
version: "1"
  - name: deploy-to-kubernetes
      - name: docker-build-and-push
          - docker build -t your-repo/your-image:latest .
          -  docker push your-repo/your-image:latest
      - name: kubernetes-deploy
          -  kubectl set image deployment/your-deployment your-container=your-repo/your-image:latest

Best Practices

  • Use Environment Variables or configs: Safeguard sensitive data like passwords and tokens as environment variables in
  • Automate Testing: Include automated testing in your CI pipeline to identify issues early.
  • Review Deployment Scripts: Consistently revisit and refine your Kubernetes deployment scripts to align with current best practices.


Integrating with Kubernetes significantly boosts the efficiency and scalability of your CI/CD pipelines. This automation makes the testing and deployment of applications, ensuring consistent and reliable software delivery.

By following a straightforward setup and best practices, you can develop a strong pipeline that meets the demands of contemporary software. Get started with our open-source workflows.