Skip to main content

Get Kubernetes Cluster Configuration

A Kubernetes cluster provisioned by the container infrastructure service exposes its kubeconfig through the vinfra CLI. There is no separate REST endpoint documented for this operation, so the CLI is the supported path.

The command prints a kubeconfig with the API server address, the cluster CA, and a client certificate, key, and token for the admin user.

Prerequisites​

  • vinfra installed on the machine that runs the command.
  • A Vietnix Cloud account with access to the project that owns the cluster.
  • The cluster name or ID.

Request​

vinfra --vinfra-domain <domain_name> \
--vinfra-project <project_name> \
--vinfra-username <username> \
--vinfra-password <password> \
service compute k8saas config <k8s_cluster_name>
vinfra-domainstringrequired

Domain the account belongs to.

vinfra-projectstringrequired

Project that owns the cluster.

vinfra-usernamestringrequired

Account username.

vinfra-passwordstringrequired

Account password.

k8s_cluster_namestringrequired

Name or ID of the Kubernetes cluster.

Response​

apiVersion: v1
clusters:
- cluster:
certificate-authority-data: <...>
server: https://10.94.129.74:6443
name: k8s1
contexts:
- context:
cluster: k8s1
user: admin
name: default
current-context: default
kind: Config
preferences: {}
users:
- name: admin
user:
client-certificate-data: <...>
client-key-data: <...>
token: <...>

Usage​

Save the output to a file and point kubectl at it:

vinfra --vinfra-domain <domain_name> \
--vinfra-project <project_name> \
--vinfra-username <username> \
--vinfra-password <password> \
service compute k8saas config k8s1 > k8s1.kubeconfig

chmod 600 k8s1.kubeconfig
export KUBECONFIG=$PWD/k8s1.kubeconfig
kubectl get nodes
warning

The kubeconfig grants cluster-admin rights. Treat it like a password: keep it out of git and out of shared notes, and rotate the cluster credentials if it leaks.

note

The API server address in the kubeconfig is a private address. Run kubectl from a network that can reach the cluster network, or set up a route or a jump host first.