<p>I have node.js application that I need to deploy to exising kubernetes cluster.</p>
<p>The cluster is setup using <code>kops</code> on AWS.</p>
<p>I have created <code>.gitlab-ci.yml</code> file for building docker images.</p>
<p>So, whenever a change is pushed to either <code>master</code> or <code>develop</code> branch. It will build the docker image.</p>
<p>I have already followed steps defined <a href="https://docs.gitlab.com/ee/user/project/clusters/add_remove_clusters.html#existing-kubernetes-cluster" rel="nofollow noreferrer">here</a> to add an existing cluster.</p>
<p>Now, I have to roll update to exisitng kubernetes cluster..</p>
<pre><code># This file is a template, and might need editing before it works on your project.
docker-build-master:
  # Official docker image.
  image: docker:latest
  stage: build
  services:
    - docker:dind
  before_script:
    - docker login -u &quot;$CI_REGISTRY_USER&quot; -p &quot;$CI_REGISTRY_PASSWORD&quot; $CI_REGISTRY
  script:
    - docker build --pull -t &quot;$CI_REGISTRY_IMAGE:prod&quot; .
    - docker push &quot;$CI_REGISTRY_IMAGE:prod&quot;
  only:
    - master

docker-build-dev:
  # Official docker image.
  image: docker:latest
  stage: build
  services:
    - docker:dind
  before_script:
    - docker login -u &quot;$CI_REGISTRY_USER&quot; -p &quot;$CI_REGISTRY_PASSWORD&quot; $CI_REGISTRY
  script:
    - docker build --pull -t &quot;$CI_REGISTRY_IMAGE:dev&quot; .
    - docker push &quot;$CI_REGISTRY_IMAGE:dev&quot;
  only:
    - develop
</code></pre>
<p>For now, I am using shared runner.</p>
<p><em>How can I integrate kubernetes deployment after image is built with gitlab ci/cd to deploy on aws (cluster is created with kops)?</em></p>
<p><em>For registry I am using gitlab's container registry not docker hub.</em></p>
<p><strong>Update</strong></p>
<p>I changed configuration and doing  below,</p>
<pre><code>stages:
  - docker-build
  - deploy

docker-build-master:
  image: docker:latest
  stage: docker-build
  services:
    - docker:dind
  before_script:
    - docker login -u &quot;$CI_REGISTRY_USER&quot; -p &quot;$CI_REGISTRY_PASSWORD&quot; $CI_REGISTRY
  script:
    - docker build --pull -t &quot;$CI_REGISTRY_IMAGE:prod&quot; .
    - docker push &quot;$CI_REGISTRY_IMAGE:prod&quot;
  only:
    - master

deploy-prod:
  stage: deploy
  image: roffe/kubectl
  script:
    - kubectl apply -f scheduler-deployment.yaml
  only:
    - master


docker-build-dev:
  image: docker:latest
  stage: docker-build
  services:
    - docker:dind
  before_script:
    - docker login -u &quot;$CI_REGISTRY_USER&quot; -p &quot;$CI_REGISTRY_PASSWORD&quot; $CI_REGISTRY
  script:
    - docker build --pull -t &quot;$CI_REGISTRY_IMAGE:dev&quot; .
    - docker push &quot;$CI_REGISTRY_IMAGE:dev&quot;
  only:
    - develop
</code></pre>
<p>But now I am getting below error.</p>
<pre><code>roffe/kubectl with digest roffe/kubectl@sha256:ba13f8ffc55c83a7ca98a6e1337689fad8a5df418cb160fa1a741c80f42979bf ...
$ kubectl apply -f scheduler-deployment.yaml
error: the path &quot;scheduler-deployment.yaml&quot; does not exist
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1

</code></pre>
<p>File <code>scheduler-deployment.yaml</code> does exist in the root directory.</p>

confusedWarrior
<blockquote>
<p>I suggest using Flux for deploying rather than invoking kubectl as part of the pipeline,</p>
</blockquote>
<p>That would be true because:</p>
<ul>
<li><p>the traditional <a href="https://docs.gitlab.com/ee/user/clusters/agent/gitops/agent.html" rel="nofollow noreferrer">GitOps with the agent for Kubernetes</a> has been deprecated with GitLab 16.2 (July 2023), and <a href="https://docs.gitlab.com/ee/user/clusters/agent/gitops.html" rel="nofollow noreferrer">replaced with Flux</a>, as shown <a href="https://docs.gitlab.com/ee/user/clusters/agent/gitops/flux_tutorial.html" rel="nofollow noreferrer">in this tutorial</a>.</p>
</li>
<li><p><a href="https://about.gitlab.com/releases/2023/08/22/gitlab-16-3-released/#flux-sync-status-visualization" rel="nofollow noreferrer">GitLab 16.3</a> (August 2023) adds:</p>
<blockquote>
<h2>Flux sync status visualization</h2>
<p>In previous releases, you probably used <code>kubectl</code> or another third-party tool to check the status of your Flux deployments. From GitLab 16.3, you can check your deployments with the environments UI.</p>
<p>Deployments rely on Flux <code>Kustomization</code> and <code>HelmRelease</code> resources to gather the status of a given environment, which requires a namespace to be configured for the environment. By default, GitLab searches the <code>Kustomization</code> and <code>HelmRelease</code> resources for the name of the project slug. You can customize the name GitLab looks for in the environment settings.</p>
<p><a href="https://i.stack.imgur.com/9hhlp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9hhlp.png" alt="https://about.gitlab.com/images/16_3/flux-badges.png -- Flux sync status visualization" /></a></p>
<p>See <a href="https://docs.gitlab.com/ee/ci/environments/kubernetes_dashboard.html#flux-sync-status" rel="nofollow noreferrer">Documentation</a> and <a href="https://gitlab.com/gitlab-org/gitlab/-/issues/391581" rel="nofollow noreferrer">Issue</a>.</p>
</blockquote>
</li>
</ul>
