<p>I am trying to create basic gitlab CICD pipeline which will deploy my node.js based backend to AWS kops based k8s cluster.For that I have created <code>gitlab-ci.yml</code> file which will use for deploy whole CICD pipeline, however I am getting confused with how to get kubernetes cluster IP address so I can use it in gitlab-ci.yml to set  as <code>- kubectl config set-cluster k8s --server=&quot;$CLUSTER_ADDRESS&quot;</code>
where I want <code>CLUSTER_ADDRESS</code> to configure with gitlab in gitlab-ci.yml.</p>
<p>Any help would be appreciated.</p>
<pre><code>variables:
  DOCKER_DRIVER: overlay2
  REGISTRY: $CI_REGISTRY
  IMAGE_TAG: $CI_REGISTRY_IMAGE
  K8S_DEPLOYMENT_NAME: deployment/$CI_PROJECT_NAME
  CONTAINER_NAME: $CI_PROJECT_NAME

stages:
  - build
  - build-docker
  - deploy


build-docker:
  image: docker:latest
  stage: build-docker
  services:
    - docker:dind
  tags:
    - privileged
  only:
    - Test
  script:
    script:
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $REGISTRY
    - docker build --network host -t $IMAGE_NAME:$IMAGE_TAG -t $IMAGE_NAME:latest .
    - docker push $IMAGE_NAME:$IMAGE_TAG
    - docker push $IMAGE_NAME:latest
deploy-k8s-(stage):
  image:
    name: kubectl:latest
    entrypoint: [&quot;&quot;]
  stage: deploy
  tags:
    - privileged
  # Optional: Manual gate
  when: manual
  dependencies:
    - build-docker
  script:
    - kubectl config set-cluster k8s --server=&quot;$CLUSTER_ADDRESS&quot;
    - kubectl config set clusters.k8s.certificate-authority-data $CA_AUTH_DATA
    - kubectl config set-credentials gitlab-service-account --token=$K8S_TOKEN
    - kubectl config set-context default --cluster=k8s --user=gitlab-service-account --namespace=default
    - kubectl config use-context default
    - kubectl set image $K8S_DEPLOYMENT_NAME $CI_PROJECT_NAME=$IMAGE_TAG
    - kubectl rollout restart $K8S_DEPLOYMENT_NAME
</code></pre>

Abhirock
<p>If your current kubeconfig context is set to the cluster in question, you can run the following to get the cluster address you want:</p>
<pre><code>kubectl config view --minify --raw \
    --output 'jsonpath={.clusters[0].cluster.server}'
</code></pre>
<p>You can add <code>--context &lt;cluster name&gt;</code> if not.</p>
<p>In most cases this will be <code>https://api.&lt;cluster name&gt;</code>.</p>
