# Connecting to EKS cluster from GitLab CI/CD

Creating a small GitLab CI/CD pipeline for deploying applications to Amazon EKS (Elastic Kubernetes Service) involves several steps

First we need to install GitLab agents in EKS cluster so that GitLab can able to communicate to EKS cluster

* In GitLab go to your subgroup and create new repository for storing config files.
    
* Folder structure : reponame/.gitlab/agents/cluster\_name/config.yaml
    

```yaml
gitops:
  manifest_projects:
  - id: rijojoseph/gitlab-agents
    default_namespace: default

ci_access:
  groups:
    - id: rijojoseph
```

You can able to see that rijojoseph is the subgroup name and gitlab-agents is the repository for storing the config files. Using above config file the EKS cluster which is going to connect is accessible across the subgroup named rijojoseph

* Go to operate --&gt; Kubernetes clusters and click on connect to cluster
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1706530273888/c1f2063a-a393-4afb-b849-abadb8879c18.png align="center")

* Select the config folder and click on register
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1706530455117/ea9eeade-e807-4c45-b3cc-73dd44ed5f4b.png align="center")

* Now you will get the steps to run after authenticating to EKS cluster from your local machine
    

```yaml
helm repo add gitlab https://charts.gitlab.io
helm repo update
helm upgrade --install test-cluster gitlab/gitlab-agent \
    --namespace gitlab-agent-test-cluster \
    --create-namespace \
    --set image.tag=v16.9.0-rc2 \
    --set config.token=glagent-XXXXXXXXXXX \
    --set config.kasAddress=wss://kas.gitlab.com
```

* After running above steps you will see the eks cluster is connected in GitLab
    
* Now you can able to use the context variable to connect to the EKS cluster from each of the repository in your subgroup
    
* You just need to add a CI/CD variable like this
    

```basic
KUBE_CONTEXT_CLUSTER_NAME : rijojoseph/gitlab-agents:test-cluster
```

* Now you can use this variable in GitLab CI/CD like this
    

```basic
kubectl config use-context ${KUBE_CONTEXT_CLUSTER_NAME}
```

* Now the GitLab CI/CD can able to run kubectl/helm commands to apply the resources to handle the deployment
