Can we access k8s-cluster-1 from another k8s cluster k8s-cluster-2?

Do we have any steps to achieve this ? ie., Acessing one k8s cluster from another k8s cluster.

Hi naraen_diran:

If the k8s-cluster-1 API is reachable from k8s-cluster-2, yes, it can be done.

To connect, you need some type of client; you can also use a containerized version of kubectl or just use curl (Access Clusters Using the Kubernetes API | Kubernetes )

Let’s assume that your k8s-cluster-1 API is available at https://k8s-cluster-1.example.org:6443/api.
You can create a Pod in your cluster 2 and run the equivalent to:

> K8S_API=https://k8s-cluster-1.example.org:6443/api
> curl -k $K8S_API
{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "Unauthorized",
  "reason": "Unauthorized",
  "code": 401
}

Even if you receive an Unauthorized reply, this reply comes from the k8s-cluster-1 API :wink: proving that we are on the right track.

The section “Without kubectl proxy” shows how to generate a TOKEN and use it to authenticate the curl requests:

# Get the token value
TOKEN=$(kubectl get secret default-token -o jsonpath='{.data.token}' | base64 --decode)

# Explore the API with TOKEN
curl -X GET $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure

Depending on why you need to access the k8s-cluster-1 from the k8s-cluster-2, you may want to consider creating a restricted user in k8s-cluster-1 to be used when accessing the k8s-cluster-1.

Hope it helps!

Xavi