Provide Context for Commands with a kubeconfig File
This page contains some basic recommendations regarding kubeconfig
as it relates to target clusters and the --kubeconfig=<CLUSTER_NAME>.conf
flag. Refer to the Kubernetes documentation for more information.
For kubectl
and dkp
commands to run, it is often necessary to specify the environment or cluster in which you want to run them. This specially applies to commands that create, delete, or update a cluster’s resources.
To specify the context, there are two options:
Export an environment variable | Specify the target cluster in the command |
---|---|
Export an environment variable from a cluster’s | Specify an environment variable for one command at the time by running it with the |
|
|
Single-cluster Environment
In a single-cluster environment, you don’t need to switch between clusters to execute commands and perform operations. However, it is still necessary to specify an environment for each terminal session, so the DKP CLI runs the operations on the DKP cluster, and does not accidentally run operations on, for example, the bootstrap cluster.
Multi-cluster Environment
Since having multiple clusters means switching between them to run operations, D2iQ recommends two approaches.
A. You can start several terminal sessions, one per cluster, and set the environment variable as shown in the single-cluster environment example above, one time per cluster.
B. You can use a single terminal session, and run the commands with a flag every time. The flag specifies the target cluster for the operation every time, so you can run the same command several times but with a different flag. Expand the following content for an explanation of option B.