Connect gitlab to kubernetes cluster hosted in rancher

6/12/2019

I am trying to connect to a rancher2 kubernetes cluster from gitlab. My kube config looks like

apiVersion: v1
kind: Config
clusters:
- name: "k8s"
  cluster:
    server: "https://..."
- name: "k8s-desktop"
  cluster:
    server: "https://192.168.0.2:6443"
    certificate-authority-data: ...

I need to point gitlab to the name.cluster.server value being https://192.168.0.2:6443, this is an internal IP. How can I override this value in kube config using my external IP so gitlab is able to connect?

-- Wouter
gitlab
kubernetes
rancher

2 Answers

6/13/2019

When you log into Rancher, you can get the kubeconfig file. This will use the Rancher url on port 443. Your kubeconfig seems to be pointing directly to your k8s node, as the kubeconfig you obtain when using RKE.

If by external ip, you mean connect from outside, then you need a device capable of port forwarding. Please clarify what you mean by internal / external ip.

From my side, i have no problem to give gitlab the Rancher url in order to connect to k8s. Rancher will proxy the connection to the k8s cluster.

-- lowmath
Source: StackOverflow

6/13/2019

I dont see any reasons to change you server ip to External. What you should do is create port forwarding from internal https://192.168.0.2:6443 to your external ip. And then use External url with port forwarded port in Gitlab Kubernetes API URL.

-- VKR
Source: StackOverflow