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:
- A Scaleway account logged into the console (External link)
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- A valid API key
- Created a Kubernetes cluster
- A machine connected to the VPC of the cluster, for example, an Instance attached to the Private Network, or a VPN connection to the VPC
Download a kubeconfig with the VPC endpoint
-
Export your API secret key. Remember to replace
<YOUR_API_SECRET_KEY>with your actual secret key.Copyexport SCW_SECRET_KEY=<YOUR_API_SECRET_KEY> -
Use the Download the kubeconfig (External link) API endpoint, and set the
endpointquery parameter tovpc. Remember to replace<region>and<cluster-ID>with the region and the ID of your cluster:Copycurl "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
kubeconfigfile whoseserverfield points to the private endpoint of the API server:- The
.internalsuffix marks the URL as the internal endpoint of the API server. This endpoint is only reachable from inside the VPC of the cluster. - Port
6443is the default HTTPS port used by the Kubernetes API server.
Example kubeconfig file:
CopyapiVersion: 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 - The
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.
-
Create an Instance and attach it to the same Private Network as your Kubernetes cluster.
-
SSH into the Instance. Remember to replace
<Instance-IP-address>with the IP of your Instance:Copyssh root@<Instace-IP-address> -
Install kubectl (External link) on the Instance.
-
Copy the contents of the kubeconfig downloaded via the API, for example to
~/.kube/kapsule-vpc-config. -
In
kapsule-vpc-config, replace thetokenvalue (REDACTED_TOKEN) with your API secret key.Change this part:
Copyuser: token: REDACTED_TOKENTo this (remember to replace
<YOUR_API_SECRET_KEY>with your actual secret key):Copyuser: token: <YOUR_API_SECRET_KEY> -
Point
kubectlto the kubeconfig file:Copyexport KUBECONFIG=~/.kube/kapsule-vpc-config -
Contact the API server:
Copykubectl get nodesIf the connection succeeds, the nodes of your cluster appear. Your
kubectlcommands 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.