# How to Use Travis CI to Deploy Applications via ArgoCD in a Kubernetes Environment?

**URL:** <https://travis-ci.community/t/how-to-use-travis-ci-to-deploy-applications-via-argocd-in-a-kubernetes-environment/14533>\
**Category:** Deployment\
**Created:** [January 27, 2025, 4:49pm UTC](https://travis-ci.community/t/how-to-use-travis-ci-to-deploy-applications-via-argocd-in-a-kubernetes-environment/14533 "2025-01-27T16:49:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mearsheimer](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/mearsheimer/32/9077_2.png) [@Mearsheimer](https://travis-ci.community/u/Mearsheimer)\
**Post date:** [January 27, 2025, 4:49pm UTC](https://travis-ci.community/t/how-to-use-travis-ci-to-deploy-applications-via-argocd-in-a-kubernetes-environment/14533/1 "2025-01-27T16:49:13Z")

</div>

I’m trying to set up a CI/CD pipeline where Travis CI handles the CI part (building and pushing Docker images) and ArgoCD takes care of the CD (deploying the application to Kubernetes). Here’s my situation:

I have a Dockerized application that I build and push to an AWS ECR repository using Travis CI. The Kubernetes manifests for the application are stored in a GitHub repository, which is already being tracked by ArgoCD. My goal is to automate the deployment process so that every time a new Docker image is built and pushed, ArgoCD triggers a sync to deploy the updated image to the Kubernetes cluster.

The challenges I’m facing include:

1. Updating the image tag in the Kubernetes manifests automatically after Travis CI builds the image.
2. Triggering ArgoCD to sync the changes without manual intervention.
3. Ensuring the process works seamlessly across multiple clusters.

I’ve come across tools like `argocd app sync` and `kustomize`, but I’m unsure how to tie these together with Travis CI. Can someone provide a clear explanation or example of how to achieve this?

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [January 27, 2025, 4:54pm UTC](https://travis-ci.community/t/how-to-use-travis-ci-to-deploy-applications-via-argocd-in-a-kubernetes-environment/14533/2 "2025-01-27T16:54:38Z")

</div>

Hi @Mearsheimer,

Use `kustomize` or a tool like `sed` to dynamically update the image tag in your Kubernetes manifests during the Travis CI build process. For example:

```auto
images:
  - name: your-app-image
    newTag: <dynamic-tag>

```

In your `.travis.yml` file, you can update the `newTag` with the Travis CI build number or commit hash. After updating the manifest files, commit the changes back to the GitHub repository tracked by ArgoCD. Use a script like this in your Travis CI pipeline:

```auto
git config --global user.email "travis@ci.org"
git config --global user.name "Travis CI"
git add .
git commit -m "Update image tag to $IMAGE_TAG"
git push origin main

```

After the updated manifests are pushed to the Git repository, you can trigger ArgoCD to sync the changes. You have two options, option one would be automated Sync, ensure ArgoCD is configured for auto-sync. It will detect changes in the repository and automatically deploy them. Option two would be manual trigger via the CLI, use the ArgoCD CLI to trigger a sync from your Travis CI pipeline. Add this command to your `.travis.yml`:

```yaml
argocd app sync your-app-name --auth-token $ARGOCD_AUTH_TOKEN --server $ARGOCD_SERVE`

```

Make sure to store `ARGOCD_AUTH_TOKEN` and `ARGOCD_SERVER` as environment variables in Travis CI.

If you’re deploying to multiple clusters, you can use a cluster-specific configuration in ArgoCD or separate applications for each cluster. Automate the updates and sync process for all clusters using the same steps. This is an `.travis.yml` I put together for you (not to follow step by step, but more as a scaffolding):

```yaml
language: bash
services:
  - docker

env:
  global:
    - IMAGE_TAG=$TRAVIS_COMMIT
    - KUBE_MANIFESTS_REPO=https://github.com/your-org/kube-manifests

script:
  - docker build -t your-ecr-repo:latest .
  - docker tag your-ecr-repo:latest your-ecr-repo:$IMAGE_TAG
  - docker push your-ecr-repo:$IMAGE_TAG

after_success:
  - git clone $KUBE_MANIFESTS_REPO
  - cd kube-manifests
  - sed -i "s|your-app-image:.*|your-app-image:$IMAGE_TAG|g" deployment.yaml
  - git add deployment.yaml
  - git commit -m "Update image tag to $IMAGE_TAG"
  - git push origin main
  - argocd app sync your-app-name --auth-token $ARGOCD_AUTH_TOKEN --server $ARGOCD_SERVER

```

This above setup in theory ensures that Travis CI builds and pushes the Docker image, updates the manifests, and triggers ArgoCD to deploy the changes automatically.

---

<div class="post-metadata">

**Author:** ![Mearsheimer](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/mearsheimer/32/9077_2.png) [@Mearsheimer](https://travis-ci.community/u/Mearsheimer)\
**Post date:** [January 28, 2025, 4:50pm UTC](https://travis-ci.community/t/how-to-use-travis-ci-to-deploy-applications-via-argocd-in-a-kubernetes-environment/14533/3 "2025-01-28T16:50:16Z")

</div>

This did it,

Thanks Montana.

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [February 3, 2025, 4:22pm UTC](https://travis-ci.community/t/how-to-use-travis-ci-to-deploy-applications-via-argocd-in-a-kubernetes-environment/14533/4 "2025-02-03T16:22:12Z")

</div>

Great,

Glad I could help you solve the problem.
