Skip to navigationSkip to main contentSkip to footerScaleway Docs HomepageAsk our AI
Ask our AI

Reaching the API server via the VPC endpoint

By default, the API server of your Kubernetes cluster is exposed via a public IP address. If this public endpoint becomes unavailable (such as during a Load Balancer outage), you lose access to cluster management.

To ensure uninterrupted access, you can communicate with the API server from within your Virtual Private Cloud (VPC). This page explains how to generate a kubeconfig configured with the private VPC endpoint of your cluster and use it to manage the control plane over your Private Network.

Before you start

To complete the following actions, you must have:

Download a kubeconfig with the VPC endpoint

  1. Export your API secret key. Remember to replace <YOUR_API_SECRET_KEY> with your actual secret key.

    export SCW_SECRET_KEY=<YOUR_API_SECRET_KEY>
  2. Use the Download the kubeconfig (External link) API endpoint, and set the endpoint query parameter to vpc. Remember to replace <region> and <cluster-ID> with the region and the ID of your cluster:

    Tip

    Add &dl=1 at the end of the URL to directly retrieve the base64-decoded kubeconfig. If you choose not to, the kubeconfig will be base64-encoded.

    curl "https://api.scaleway.com/k8s/v1/regions/<region>/clusters/<cluster-ID>/kubeconfig?endpoint=vpc&redacted=true&dl=1" -H "X-Auth-Token: $SCW_SECRET_KEY"

    The command returns a kubeconfig file whose server field points to the private endpoint of the API server:

    • The .internal suffix marks the URL as the internal endpoint of the API server. This endpoint is only reachable from inside the VPC of the cluster.
    • Port 6443 is the default HTTPS port used by the Kubernetes API server.

    Example kubeconfig file:

    apiVersion: v1
    clusters:
    - name: "my-cluster"
      cluster:
        certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSU...ZmV0YQ
        server: https://a92d5ceb-21b9-...c101342c-0a0a-....internal:6443
    contexts:
    - name: admin@my-cluster
      context:
        cluster: "my-cluster"
        user: my-cluster-admin
    current-context: admin@my-cluster
    kind: Config
    preferences: {}
    users:
    - name: my-cluster-admin
      user:
        token: REDACTED_TOKEN

Use the kubeconfig from inside the VPC

The private endpoint of the API server is only reachable from inside the VPC of your cluster. If you run kubectl from a machine that is not attached to the VPC, the connection times out. Connect to the VPC first, for example from an Instance attached to the Private Network.

  1. Create an Instance and attach it to the same Private Network as your Kubernetes cluster.

  2. SSH into the Instance. Remember to replace <Instance-IP-address> with the IP of your Instance:

    ssh root@<Instace-IP-address>
  3. Install kubectl (External link) on the Instance.

  4. Copy the contents of the kubeconfig downloaded via the API, for example to ~/.kube/kapsule-vpc-config.

  5. In kapsule-vpc-config, replace the token value (REDACTED_TOKEN) with your API secret key.

    Change this part:

    user:
      token: REDACTED_TOKEN

    To this (remember to replace <YOUR_API_SECRET_KEY> with your actual secret key):

    user:
      token: <YOUR_API_SECRET_KEY>
  6. Point kubectl to the kubeconfig file:

    export KUBECONFIG=~/.kube/kapsule-vpc-config
  7. Contact the API server:

    kubectl get nodes

    If the connection succeeds, the nodes of your cluster appear. Your kubectl commands now reach the API server over the private VPC endpoint, giving you a reliable path to your cluster that does not depend on the public IP of the API server.

Still need help?

Create a support ticket
No Results