<p>I have a <code>.gitlab-ci.yml</code> file in which I want to do the following:</p>
<ol>
<li>Build a Docker image and push it to AWS ECR</li>
<li>Restart a specific deployment in my EKS cluster that uses this Docker image</li>
</ol>
<p>Building and pushing the Docker image works fine, however I'm failing to connect to my EKS cluster.</p>
<p>My idea is to use <code>aws eks</code> to update my kubeconfig file, and <code>kubectl</code> to restart my deployment, but I don't know how to use the AWS CLI and Kubectl in my <code>.gitlab-ci.yml</code> file.</p>
<p>I have <code>AWS_ACCESS_KEY_ID</code>, <code>AWS_ACCOUNT_ID</code>, and <code>AWS_DEFAULT_REGION</code> defined in my CI/CD variables. I've got the following <code>.gitlab-ci.yml</code> file:</p>
<pre><code>stages:
  - build
  - deploy staging

&lt;build stage omitted for brevity&gt;

staging:
  stage: deploy staging
  image: bitnami/kubectl:latest
  only:
    - staging
  script: |
    # install AWS CLI
    apk add --no-cache python3 py3-pip \
      &amp;&amp; pip3 install --upgrade pip \
      &amp;&amp; pip3 install awscli \
      &amp;&amp; rm -rf /var/cache/apk/*
    aws eks update-kubeconfig --region eu-west-1 --name my-cluster-name
    kubectl rollout restart deployment my-deployment

</code></pre>
<p>This pipeline fails with the error:</p>
<pre><code>error: unknown command &quot;sh&quot; for &quot;kubectl&quot;
Did you mean this?
    set
    cp
</code></pre>
<p>I've found <a href="https://gitlab.com/gitlab-org/gitlab-foss/-/issues/65110" rel="nofollow noreferrer">this issue and solution</a>, but changing the <code>.gitlab-ci.yml</code> file accordingly prevents me from using <code>apk</code> and installing the AWS cli:</p>
<pre><code>stages:
  - build
  - deploy staging

&lt;build stage omitted for brevity&gt;

staging:
  stage: deploy staging
  image:
    name: bitnami/kubectl:latest
    entrypoint: [&quot;&quot;]
  only:
    - staging
  script: |
    # install AWS CLI
    apk add --no-cache python3 py3-pip \
      &amp;&amp; pip3 install --upgrade pip \
      &amp;&amp; pip3 install awscli \
      &amp;&amp; rm -rf /var/cache/apk/*
    aws eks update-kubeconfig --region eu-west-1 --name my-cluster-name
    kubectl rollout restart deployment my-deployment

</code></pre>
<p>Results in the error:</p>
<pre><code>$ # install AWS CLI # collapsed multi-line command
/bin/bash: line 140: apk: command not found
/bin/bash: line 144: aws: command not found
</code></pre>
<p>So that leads me to the following question: how do I use both the AWS CLI and Kubectl in my <code>.gitlab-ci.yml</code> file? Or is there another easier way that allows me to restart a deployment in my EKS cluster?</p>

Kasper Kooijman
<p>I solved it myself. For future readers: using the <a href="https://hub.docker.com/r/alpine/k8s" rel="nofollow noreferrer">alpine/k8s</a> image solves my problem. It has both Kubectl and AWScli installed.</p>
