Update How to use the Kubernetes Agent to connect your app to a cluster authored by Corina Patachia's avatar Corina Patachia
**This page is meant to help with code and snippets to connect to a Kubernetes cluster using the K8 Agent. This connection doesn't use a tunnel.** **This page is meant to help with code and snippets to connect to a Kubernetes cluster using the K8 Agent. This connection doesn't use a tunnel.**
Before you get started : Before you get started :
- you need a Kubernetes cluster running and kubectl installed
- you need a Kubernetes cluster running and kubectl installed
Steps to reproduce : Steps to reproduce :
1. Containerize your application with a Dockerfile. In the example we provide we start with a base alpine node image and set the working directory, install the packages we need and then copy everything in the container at line 15. The app is running at like 17. We have a react app so we added 2 arguments in the dockerfile, especially for js apps. 1. Containerize your application with a [Dockerfile](https://gitlab.com/corina-s/how-fast-can-flash-run/-/snippets/2415246). In the example we provide we start with a base alpine node image and set the working directory, install the packages we need and then copy everything in the container at[ line 10](https://gitlab.com/corina-s/how-fast-can-flash-run/-/snippets/2415246#LC10). The app is running at[ line 14](https://gitlab.com/corina-s/how-fast-can-flash-run/-/snippets/2415246#LC14). We have a react app so we added 2 arguments in the dockerfile, especially for js apps.
2. Now it's time to create the actual agent. In your GitLab project, go to `> Infrastructure > Kubernetes Cluster` and click on `Connect a cluster ( agent )` button. 2. Now it's time to create the actual agent. In your GitLab project, go to `> Infrastructure > Kubernetes Cluster` and click on `Connect a cluster ( agent )` button.
3. Create a new agent by typing in a unique name for the agent and clicking create. 3. Create a new agent by typing in a unique name for the agent and clicking create.
4. **!!! Important !!!** After you create the Agent, GitLab shares a token and some helm commands to connect the agent to the cluster with the newly generated token. Please copy the commands in the popup before you close it. 4. **!!! Important !!!** After you create the Agent, GitLab shares a token and some helm commands to connect the agent to the cluster with the newly generated token. Please copy the commands in the popup before you close it.
5. connect to your Kubernetes cluster via the terminal and execute the helm commands with the agent token that you have copied at the previous step. 5. Connect to your Kubernetes cluster via the terminal and execute the helm commands with the agent token you copied at the previous step. If this was successful you should see this response
6.
\ No newline at end of file `Release "<your-agent-name-here>" has been upgraded. Happy Helming!`
6. Next, you need to add ingress to your Kubernetes cluster. Execute the following commands from the same terminal
`helm repo add ingress-nginx` `https://kubernetes.github.io/ingress-nginx`\
[`helm`](https://kubernetes.github.io/ingress-nginxhelm) `repo update`\
To check if the commands above were successful you should see this response\
`...Successfully got an update from the "ingress-nginx" chart repository ...Successfully got an update from the "gitlab" chart repository Update Complete. ⎈Happy Helming!⎈`
7. Now that we have added ingress to our cluster we need to give it a name and also install it
`helm install <your-namre-here> ingress-nginx/ingress-nginx`
8. Ingress has been installed with default configuration, we need to make sure that our cluster is aware of it
`kubectl get svc --all-namespaces -o jsonpath='{range.items\[?(@.status.loadBalancer.ingress)\]}{.status.loadBalancer.ingress\[\*\].ip} '`
\ No newline at end of file