Commands and Tools to Access kubeconfig File
To perform actions on the file we use kubectl followed by config and then specify the operations. For editing the file we can make use of vim editor or open the file in notepad and make the necessary changes. Some of them are as follows.
1. kubectl config current-context
To view the current context we use the command kubectl config current-context
Here minikube is our current context
2. kubectl config get-contexts
To get list of all contexts we use kubectl config get-contexts
Here we get all the details including name, cluster, Author info and Namespace.
3. kubectl config get-clusters
To get list of clusters we use this command
As we can see the cluster name is minikube.
4. kubectl config use-context <context-name>
To switch to a different context as specified in the config file.
5. kubectl config set-cluster <cluster-name> –server=<server> –certificate-authority=<path-to-ca-cert>
To add a new cluster along with other details. However we can provide certificate details later on as per our requirement.
Here e2e is our new cluster.
6. kubectl config set-credentials <user-name> –client-certificate=<path-to-client-cert> –client-key=<path-to-client-key>
To add a new user along with other necessary details. Here also we can provide additional details later on.
7. kubectl config set-context <context-name> –cluster=<cluster-name> –user=<user-name> –namespace=<namespace>
To add a new context to the file. We can provide namespace details later as well
Commands |
Use |
---|---|
kubectl config current-context |
To view the current context |
kubectl config get-contexts |
Get list of all contexts |
kubectl config get-clusters |
Get list of clusters |
kubectl config use-context <context-name> |
To switch to a different context as specified in cconfig file |
kubectl config set-cluster <cluster-name> –server=<server> –certificate-authority=<path-to-ca-cert> |
To add a new cluster along with other details |
kubectl config set-credentials <user-name> –client-certificate=<path-to-client-cert> –client-key=<path-to-client-key> |
To add a new user along with other necessary details |
kubectl config set-context <context-name> –cluster=<cluster-name> –user=<user-name> –namespace=<namespace> |
To add a new context to the file |
There are different tools available However the most commonly used ones are text editors like Notepad, vim editor etc.
- To make further changes to kubeconfig file locate the file in the location C:\Users\<username>\.kube\.
- Then open the file in notepad.
- Make the changes accordingly.
What is kubernetes kubeconfig ?
The container is a package that comprises code and libraries that are to be executed. Now to automate the deployment of Containers we need Kubernetes or K8s. Kubernetes or K8s is an open source that is used for the deployment of containers. It is a container orchestration platform that is used to automate the deployment of containers. They help to manage, schedule, and scale the applications. Kubernetes should be confused with cloud services. They are basically integrated with cloud services in order to generate comprehensive solutions.
If we go through the structure, Kubernetes basically makes use of clusters. Inside clusters there exists nodes or physical machines. Inside those physical machines are pods. Inside pods, there exist containers.
Contact Us