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 kubeconfig file, which sets the environment for the commands you run after exporting it. | Specify an environment variable for one command at the time by running it with the --kubeconfig=${CLUSTER_NAME}.conf flag. |
| |
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 cluster with the Kommander component.
Use a kubeconfig file to set the environment variable for all your operations
Set the environment variable for all your operations
When you create a cluster, a kubeconfig
file is generated automatically. Get this kubeconfig
file and write it to the ${CLUSTER_NAME}.conf
variable:
CODE
dkp get kubeconfig -c ${CLUSTER_NAME} > ${CLUSTER_NAME}.conf
After setting this configuration, whenever you use run a command with the variable ${CLUSTER_NAME}.conf
, it will automatically run on your cluster.
Set the context by exporting your kubeconfig
from the source file:
:note: Execute this command for each terminal session.
CODE
export KUBECONFIG=${CLUSTER_NAME}.conf
For the current terminal session, you don’t need to provide the --kubeconfig
flag.
Multi-cluster Environment
Since having multiple clusters means switching between them to run operations, D2iQ recommends using the flag to set the context.
Use a flag to reference the target cluster
Use a flag to reference the target cluster
The --kubeconfig ${CLUSTER_NAME}.conf
flag defines the configuration file for the cluster that you are configuring and accessing.
When operating and using multiple clusters, this is the easiest way to ensure that you are working on the correct cluster. If you create additional clusters and do not store the name as an environment variable, you can type out the name of the cluster followed by .conf
to access your cluster.
Ensure you run dkp get kubeconfig
for each cluster you create to generate a kubeconfig
file.
Example flag:
CODE
--kubeconfig azurecluster1.conf
Example command with flag:
CODE
dkp install kommander --kubeconfig azurecluster1.conf
Next Topic:
Storage