{"id":564,"date":"2025-05-30T01:32:00","date_gmt":"2025-05-30T01:32:00","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=564"},"modified":"2025-05-30T01:32:00","modified_gmt":"2025-05-30T01:32:00","slug":"kubernetes-kubeconfig-file","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=564","title":{"rendered":"Kubeconfig File Explained (Examples, Usage and Configuration)"},"content":{"rendered":"<p>In this blog, you\u2019ll learn what a Kubeconfig file is and how to create and use one to connect to a Kubernetes cluster with hands-on examples.<\/p>\n<p>By the end of this guide, you will learn:<\/p>\n<ul>\n<li>What a kubeconfig file is<\/li>\n<li>How to use it to connect to Kubernetes clusters<\/li>\n<li>How to create a custom kubeconfig file<\/li>\n<li>How to merge multiple kubeconfig files.<\/li>\n<li>How to secure the kubeconfig files.<\/li>\n<\/ul>\n<h2 id=\"what-is-a-kubeconfig-file\">What is a Kubeconfig file?<\/h2>\n<p>A <strong>Kubeconfig is a YAML file<\/strong> with all the <a href=\"https:\/\/devopscube.com\/setup-kubernetes-cluster-kubeadm\/\">Kubernetes cluster<\/a> details, certificates, and secret tokens to authenticate the cluster. You might get this config file directly from the cluster administrator or from a cloud platform if you are using a managed Kubernetes cluster.<\/p>\n<p>When you use <code>kubectl<\/code>, it uses the information in the kubeconfig file to connect to the kubernetes cluster API. The default location of the Kubeconfig file is <code>$HOME\/.kube\/config<\/code><\/p>\n<figure class=\"kg-card kg-image-card kg-card-hascaption\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/05\/image-55.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"745\" height=\"735\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/05\/image-55.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/05\/image-55.png 745w\" sizes=\"auto, (min-width: 720px) 720px\"><figcaption><span style=\"white-space: pre-wrap;\">kubeconfig file for cluster access<\/span><\/figcaption><\/figure>\n<p>Not just users, any cluster component that need to authenticate to the kubernetes API server need the&nbsp;kubeconfig file.<\/p>\n<p>For example, <a href=\"https:\/\/devopscube.com\/kubernetes-architecture-explained\/\">kubernetes cluster components<\/a> like controller manager, scheduler and kubelet use the kubeconfig files to interact with the API server.<\/p>\n<p>All the cluster Kubeconfig files are present in the control plane <code><strong>\/etc\/kubernetes<\/strong><\/code>&nbsp;folder (<code>.conf<\/code> files).<\/p>\n<div class=\"kg-card kg-callout-card kg-callout-card-blue\">\n<div class=\"kg-callout-emoji\">\ud83d\udccc<\/div>\n<div class=\"kg-callout-text\">Looking for an organized way to learn Kubernetes and prepare for the CKA exam ?<\/p>\n<p>Check out our&nbsp;<a href=\"https:\/\/techiescamp.com\/p\/cka-complete-prep-course-practice-tests?ref=devopscube.com\" target=\"_blank\" rel=\"noreferrer noopener\">CKA course and practice test bundle<\/a>&nbsp;(Use code <b><strong style=\"white-space: pre-wrap;\">DCUBE25<\/strong><\/b> to get 25% OFF today).<\/p>\n<p>We explain concepts using illustrations, hands-on exercises, real-world examples, and provide dedicated discord based user support.<\/p><\/div>\n<\/div>\n<h2 id=\"example-kubeconfig-file\">Example Kubeconfig File<\/h2>\n<p>Here is an example of a Kubeconfig. It needs the following key information to connect to the Kubernetes clusters.<\/p>\n<ol>\n<li><strong>certificate-authority-data<\/strong>:  Cluster CA<\/li>\n<li><strong>server<\/strong>: Cluster endpoint (IP\/DNS of the master node)<\/li>\n<li><strong>name<\/strong>: Cluster name<\/li>\n<li><strong>user<\/strong>: name of the user\/service account.<\/li>\n<li><strong>token<\/strong>: Secret token of the user\/service account.<\/li>\n<\/ol>\n<pre><code class=\"language-yaml\">apiVersion: v1\nclusters:\n- cluster:\n    certificate-authority-data: &lt;ca-data-here&gt;\n    server: https:\/\/your-k8s-cluster.com\n  name: &lt;cluster-name&gt;\ncontexts:\n- context:\n    cluster:  &lt;cluster-name&gt;\n    user:  &lt;cluster-name-user&gt;\n  name:  &lt;cluster-name&gt;\ncurrent-context:  &lt;cluster-name&gt;\nkind: Config\npreferences: {}\nusers:\n- name:  &lt;cluster-name-user&gt;\n  user:\n    token: &lt;secret-token-here&gt;\n<\/code><\/pre>\n<h2 id=\"kubeconfig-file-usage\">Kubeconfig File Usage<\/h2>\n<p>You can use the k<code>ubeconfig<\/code> in different ways and each way has its own precedence. <\/p>\n<p>Here is the precedence in order.<\/p>\n<ol>\n<li><strong>Kubectl Context:<\/strong> Kubeconfig with kubectl overrides all other configs. It has the highest precedence.<\/li>\n<li><strong>Environment Variable:<\/strong> KUBECONFIG env variable overrides the current context.<\/li>\n<li><strong>Command-Line Reference: <\/strong>The current context has the least precedence over the inline config reference and env variable.<\/li>\n<\/ol>\n<p>Now let&#8217;s take a look at all <strong>three ways to use the Kubeconfig file.<\/strong><\/p>\n<h3 id=\"method-1-using-kubeconfig-with-kubectl-context\">Method 1: Using Kubeconfig with Kubectl Context<\/h3>\n<p>To connect to the Kubernetes cluster, the basic prerequisite is the Kubectl CLI plugin. If you don&#8217;t have the CLI installed, follow the <a href=\"https:\/\/kubernetes.io\/docs\/tasks\/tools\/install-kubectl-linux\/?ref=devopscube.com\" rel=\"noreferrer noopener\">instructions given here<\/a>.<\/p>\n<p>Now follow the steps given below to use the kubeconfig file to interact with the cluster.<\/p>\n<h4 id=\"step-1-move-kubeconfig-to-kube-directory\">Step 1: Move kubeconfig to .kube directory.<\/h4>\n<p>Kubectl interacts with the kubernetes cluster using the details available in the Kubeconfig file. By default, kubectl looks for the config file in the <code>\/.kube<\/code> location.<\/p>\n<p>Let&#8217;s move the kubeconfig file to the .kube directory. Replace <code>\/path\/to\/kubeconfig<\/code> with your kubeconfig current path.<\/p>\n<pre><code class=\"language-bash\">mv \/path\/to\/kubeconfig ~\/.kube<\/code><\/pre>\n<h4 id=\"step-2-list-all-cluster-contexts\">Step 2: List all cluster contexts<\/h4>\n<p>You can have any number of kubeconfig in the <code>.kube<\/code> directory. Each config will have a unique context name (ie, the name of the cluster). You can validate the Kubeconfig file by listing the contexts. You can list all the contexts using the following command. It will list the context name as the name of the cluster.<\/p>\n<pre><code class=\"language-bash\">kubectl config get-contexts -o=name<\/code><\/pre>\n<h4 id=\"step-3-switch-kubernetes-contex\">Step 3: Switch Kubernetes contex<\/h4>\n<p>Now you need to <a href=\"https:\/\/devopscube.com\/kubectl-set-context\/\">set the current context<\/a> to your kubeconfig file. You can set that using the following command. replace <code>&lt;cluster-name&gt;<\/code> with your listed context name.<\/p>\n<pre><code class=\"language-bash\">kubectl config use-context &lt;cluster-name&gt;  <\/code><\/pre>\n<p>For example,<\/p>\n<pre><code class=\"language-bash\">kubectl config use-context my-dev-cluster<\/code><\/pre>\n<h4 id=\"step-4-validate-the-kubernetes-cluster-connectivity\">Step 4: Validate the Kubernetes cluster connectivity<\/h4>\n<p>To validate the cluster connectivity, you can execute the following kubectl command to list the cluster nodes.<\/p>\n<pre><code class=\"language-bash\">kubectl get nodes<\/code><\/pre>\n<h3 id=\"method-2-using-kubeconfig-environment-variable\">Method 2: Using KUBECONFIG environment variable<\/h3>\n<p>You can set the <code>KUBECONFIG<\/code> environment variable with the <code>kubeconfig<\/code> file path to connect to the cluster. So wherever you are using the kubectl command from the terminal, the <code>KUBECONFIG<\/code> env variable should be available. If you set this variable, it overrides the current cluster context.<\/p>\n<p>You can set the variable using the following command. Where <code>dev_cluster_config <\/code>is the <code>kubeconfig<\/code> file name.<\/p>\n<pre><code class=\"language-bash\">export KUBECONFIG=$HOME\/.kube\/dev_cluster_config<\/code><\/pre>\n<h3 id=\"method-3-using-kubeconfig-file-with-kubectl\">Method 3: Using Kubeconfig File With Kubectl<\/h3>\n<p>You can pass the Kubeconfig file with the Kubectl command to override the current context and KUBECONFIG env variable.<\/p>\n<p>Here is an example to get nodes.<\/p>\n<pre><code class=\"language-bash\">kubectl get nodes --kubeconfig=$HOME\/.kube\/dev_cluster_config<\/code><\/pre>\n<p>Also, you can use,<\/p>\n<pre><code class=\"language-bash\">KUBECONFIG=$HOME\/.kube\/dev_cluster_config kubectl get nodes<\/code><\/pre>\n<h2 id=\"merge-multiple-kubeconfig-files\">Merge Multiple Kubeconfig Files<\/h2>\n<p>Usually, when you work with multiple Kubernetes clusters, all the cluster contexts get added as a single file. <\/p>\n<p>However, there are situations where you will be given a <code>Kubeconfig<\/code> file with limited access to connect to prod or non-prod servers.<\/p>\n<p>To manage all clusters effectively using a single config, you can merge the other Kubeconfig files to the default <code>$HOME\/.kube\/config<\/code> file using the supported kubectl command.<\/p>\n<p>Let&#8217;s assume you have three Kubeconfig files in the <code>$HOME\/.kube\/<\/code> directory.<\/p>\n<ol>\n<li>config (default kubeconfig)<\/li>\n<li>dev_config<\/li>\n<li>test_config<\/li>\n<\/ol>\n<p>You can merge all three configs into a single file using the following command. Ensure you are running the command from the <code>HOME\/ .kube<\/code> directory.<\/p>\n<pre><code class=\"language-bash\">KUBECONFIG=config:dev_config:test_config kubectl config view --merge --flatten &gt; config.new<\/code><\/pre>\n<p>The above command creates a merged config named <code>config.new<\/code>.<\/p>\n<p>Now rename the old  <strong><code>$HOME.kube\/config<\/code><\/strong> file.<\/p>\n<pre><code class=\"language-bash\"> mv $HOME\/.kube\/config $HOME\/.kube\/config.old<\/code><\/pre>\n<p>Rename the <code>config.new<\/code> to config.<\/p>\n<pre><code class=\"language-bash\">mv $HOME\/.kube\/config.new $HOME\/.kube\/config<\/code><\/pre>\n<p>To verify the configuration, try listing the contexts from the config.<\/p>\n<pre><code>kubectl config get-contexts -o name<\/code><\/pre>\n<p>If you want to view the kubeconfig file in a condensed format to analyze all the configurations, you can use the following minify command.<\/p>\n<pre><code class=\"language-bash\">kubectl config view --minify<\/code><\/pre>\n<h2 id=\"delete-cluster-context-from-kubeconfig\">Delete Cluster Context From Kubeconfig<\/h2>\n<p>There are scenarios where you might have context added to the kubeconfig file and the cluster gets deleted.<\/p>\n<p>In this scenario, you might want to remove the context from the Kubeconfig file. Here is how you can do it.<\/p>\n<p>First, list the contexts.<\/p>\n<pre><code class=\"language-bash\">kubectl config get-contexts -o=name<\/code><\/pre>\n<p>Get the context name and delete it using the following command. Replace <strong>&lt;context-name&gt;<\/strong> with your context name.<\/p>\n<pre><code class=\"language-bash\">kubectl config delete-context &lt;context-name&gt;<\/code><\/pre>\n<p>You can set a new context of existing clusters using,<\/p>\n<pre><code class=\"language-bash\">kubectl config use-context &lt;context-name&gt;<\/code><\/pre>\n<h2 id=\"creating-a-kubeconfig-file\">Creating a Kubeconfig File<\/h2>\n<p>There are scenarios in real time project environments where you need to provide Kubeconfig files to developers or other teams to connect to clusters for specific use cases. It could be user access or for apps.<\/p>\n<p>Now we will look at creating Kubeconfig files using the serviceaccount method. serviceaccount is the default user type managed by Kubernetes API.<\/p>\n<p>A kubeconfig needs the following important details.<\/p>\n<ol>\n<li>Cluster endpoint (IP or DNS name of the cluster)<\/li>\n<li>Cluster CA Certificate<\/li>\n<li>Cluster name<\/li>\n<li>Service account user name<\/li>\n<li>Service account token<\/li>\n<\/ol>\n<div class=\"kg-card kg-callout-card kg-callout-card-blue\">\n<div class=\"kg-callout-emoji\">\ud83d\udca1<\/div>\n<div class=\"kg-callout-text\"><b><strong style=\"white-space: pre-wrap;\">Note<\/strong><\/b>: To generate a Kubeconfig file, you need to have admin permissions in the cluster to create service accounts and roles.<\/div>\n<\/div>\n<p>For this demo, I am creating a service account with <code>clusterRole<\/code> that has limited access to cluster-wide resources. You can also create a normal role and Rolebinding that limits the user&#8217;s access to a specific namespace.<\/p>\n<h3 id=\"step-1-create-a-service-account\">Step 1: Create a Service Account<\/h3>\n<p>The service account name will be the user name in Kubeconfig. Here I am creating the service account in the <code>kube-system<\/code> as I am creating a clusterRole. If you want to create a config to give namespace level limited access, create the service account in the required namespace.<\/p>\n<pre><code class=\"language-bash\">kubectl -n kube-system create serviceaccount devops-cluster-admin<\/code><\/pre>\n<h3 id=\"step-2-create-a-secret-object-for-the-service-account\">Step 2: Create a Secret Object for the Service Account<\/h3>\n<p>From Kubernetes Version 1.24, the secret for the service account has to be created separately with an annotation <code>kubernetes.io\/service-account.name<\/code> and type <code>kubernetes.io\/service-account-token<\/code><\/p>\n<p>Let&#8217;s create a secret named <strong>devops-cluster-admin-secret<\/strong> with the annotation and type.<\/p>\n<pre><code class=\"language-yaml\">cat &lt;&lt; EOF | kubectl apply -f -\napiVersion: v1\nkind: Secret\nmetadata:\n  name: devops-cluster-admin-secret\n  namespace: kube-system\n  annotations:\n    kubernetes.io\/service-account.name: devops-cluster-admin\ntype: kubernetes.io\/service-account-token\nEOF<\/code><\/pre>\n<h3 id=\"step-3-create-a-clusterrole\">Step 3: Create a ClusterRole<\/h3>\n<p>Let&#8217;s create a <code>clusterRole<\/code> with limited privileges to cluster objects. You can add the required object access as per your requirements. Refer to the s<a href=\"https:\/\/devopscube.com\/kubernetes-api-access-service-account\/\" rel=\"noreferrer noopener\">ervice account with clusterRole access<\/a> blog for more information.<\/p>\n<p>If you want to create a namespace-scoped role, refer to <a href=\"https:\/\/devopscube.com\/create-kubernetes-role\/\" rel=\"noreferrer noopener\">creating service account with role<\/a>.<\/p>\n<p>Execute the following command to create the clusterRole.<\/p>\n<pre><code class=\"language-yaml\">cat &lt;&lt; EOF | kubectl apply -f -\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRole\nmetadata:\n  name: devops-cluster-admin\nrules:\n- apiGroups: [\"\"]\n  resources:\n  - nodes\n  - nodes\/proxy\n  - services\n  - endpoints\n  - pods\n  verbs: [\"get\", \"list\", \"watch\"]\n- apiGroups:\n  - extensions\n  resources:\n  - ingresses\n  verbs: [\"get\", \"list\", \"watch\"]\nEOF<\/code><\/pre>\n<h3 id=\"step-4-create-clusterrolebinding\">Step 4: Create ClusterRoleBinding<\/h3>\n<p>The following YAML is a ClusterRoleBinding that binds the <code>devops-cluster-admin<\/code> service account with the <code>devops-cluster-admin<\/code> clusterRole.<\/p>\n<pre><code class=\"language-yaml\">cat &lt;&lt; EOF | kubectl apply -f -\napiVersion: rbac.authorization.k8s.io\/v1\nkind: ClusterRoleBinding\nmetadata:\n  name: devops-cluster-admin\nroleRef:\n  apiGroup: rbac.authorization.k8s.io\n  kind: ClusterRole\n  name: devops-cluster-admin\nsubjects:\n- kind: ServiceAccount\n  name: devops-cluster-admin\n  namespace: kube-system\nEOF<\/code><\/pre>\n<h3 id=\"step-5-get-all-cluster-details-secrets\">Step 5: Get all Cluster Details &amp; Secrets<\/h3>\n<p>We will retrieve all the required kubeconfig details and save them in variables. Then, finally, we will substitute it directly with the Kubeconfig YAML.<\/p>\n<p>If you have used a different secret name, replace <strong><code>devops-cluster-admin-secret<\/code><\/strong> with your secret name,<\/p>\n<pre><code class=\"language-bash\">export SA_SECRET_TOKEN=$(kubectl -n kube-system get secret\/devops-cluster-admin-secret -o=go-template='{{.data.token}}' | base64 --decode)\n\nexport CLUSTER_NAME=$(kubectl config current-context)\n\nexport CURRENT_CLUSTER=$(kubectl config view --raw -o=go-template='{{range .contexts}}{{if eq .name \"'''${CLUSTER_NAME}'''\"}}{{ index .context \"cluster\" }}{{end}}{{end}}')\n\nexport CLUSTER_CA_CERT=$(kubectl config view --raw -o=go-template='{{range .clusters}}{{if eq .name \"'''${CURRENT_CLUSTER}'''\"}}\"{{with index .cluster \"certificate-authority-data\" }}{{.}}{{end}}\"{{ end }}{{ end }}')\n\nexport CLUSTER_ENDPOINT=$(kubectl config view --raw -o=go-template='{{range .clusters}}{{if eq .name \"'''${CURRENT_CLUSTER}'''\"}}{{ .cluster.server }}{{end}}{{ end }}')<\/code><\/pre>\n<h3 id=\"step-6-generate-the-kubeconfig-with-the-variables\">Step 6: Generate the Kubeconfig With the variables.<\/h3>\n<p>If you execute the following YAML, all the variables get substituted and a config named  <code>devops-cluster-admin-config<\/code> gets generated.<\/p>\n<pre><code class=\"language-bash\">cat &lt;&lt; EOF &gt; devops-cluster-admin-config\napiVersion: v1\nkind: Config\ncurrent-context: ${CLUSTER_NAME}\ncontexts:\n- name: ${CLUSTER_NAME}\n  context:\n    cluster: ${CLUSTER_NAME}\n    user: devops-cluster-admin\nclusters:\n- name: ${CLUSTER_NAME}\n  cluster:\n    certificate-authority-data: ${CLUSTER_CA_CERT}\n    server: ${CLUSTER_ENDPOINT}\nusers:\n- name: devops-cluster-admin\n  user:\n    token: ${SA_SECRET_TOKEN}\nEOF<\/code><\/pre>\n<h3 id=\"step-7-validate-the-generated-kubeconfig\">Step 7: Validate the generated Kubeconfig<\/h3>\n<p>To validate the Kubeconfig, execute it with the kubectl command to see if the cluster is getting authenticated.<\/p>\n<pre><code class=\"language-bash\">kubectl get nodes --kubeconfig=devops-cluster-admin-config <\/code><\/pre>\n<div class=\"kg-card kg-callout-card kg-callout-card-blue\">\n<div class=\"kg-callout-emoji\">\ud83d\udca1<\/div>\n<div class=\"kg-callout-text\"><b><strong style=\"white-space: pre-wrap;\">Note<\/strong><\/b>: In cloud environments, cluster RBAC (Role-Based Access Control) can be mapped with normal IAM (Identity and Access Management) users. This allows organizations to control access to the cluster based on IAM policies, which can be used to create restrictive kubeconfig files. <\/p>\n<p>Additionally, other services, such as <a href=\"https:\/\/openid.net\/connect\/?ref=devopscube.com\" rel=\"noreferrer noopener\">OIDC<\/a> (OpenID Connect), can be used to manage users and create kubeconfig files that limit access to the cluster based on specific security requirements.<\/div>\n<\/div>\n<h2 id=\"security-best-practices\">Security Best Practices<\/h2>\n<p>Always ensure you follow the following security best practices for Kubeconfig files.<\/p>\n<h3 id=\"securing-kubeconfig-files\">Securing Kubeconfig Files<\/h3>\n<p>Your kubeconfig file holds sensitive details like tokens and certificates, so it should only be accessible to you. Make sure you&#8217;re the only one who can read or modify it.<\/p>\n<p>If your Kubeconfig file is not secure, you will get the following error while using kubectl.<\/p>\n<pre><code class=\"language-bash\">WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: \/Users\/bibinwilson\/.kube\/config<\/code><\/pre>\n<p>Using the following commands, you can set and verify restrictive permissions.<\/p>\n<pre><code class=\"language-bash\"># Set restrictive permissions (owner read\/write only)\nchmod 600 ~\/.kube\/config\n\n# Verify permissions\nls -la ~\/.kube\/config\n# Should show: -rw------- 1 user user\n\n# For multiple configs\nfind ~\/.kube -name \"*.config\" -exec chmod 600 {} \\;<\/code><\/pre>\n<p>You can also lock down the entire <code>.kube<\/code> directory to make sure no one else can read from or write to it.<\/p>\n<pre><code class=\"language-bash\">chmod 700 ~\/.kube\nchown -R $USER ~\/.kube<\/code><\/pre>\n<h3 id=\"prevent-accidental-exposure\">Prevent accidental exposure<\/h3>\n<p>If you\u2019re working in a Git repo, avoid committing sensitive kubeconfig files by adding it to the <code>.gitignore<\/code> file.<\/p>\n<pre><code class=\"language-bash\">echo \"\/.kube\/\" &gt;&gt; ~\/.gitignore\necho \"kubeconfig*\" &gt;&gt; ~\/.gitignore<\/code><\/pre>\n<h2 id=\"kubeconfig-file-faqs\">Kubeconfig File FAQs<\/h2>\n<p>Let&#8217;s look at some of the frequently asked Kubeconfig file questions.<\/p>\n<h3 id=\"where-do-i-put-the-kubeconfig-file\">Where do I put the Kubeconfig file?<\/h3>\n<p>The default Kubeconfig file location is <code><strong>$HOME\/.kube\/<\/strong><\/code> folder in the home directory. Kubectl looks for the kubeconfig file using the context name from the .<code>kube<\/code> folder. However, if you are using the <code>KUBECONFIG<\/code> environment variable, you can place the kubeconfig file in a preferred folder and refer to the path in the <code>KUBECONFIG<\/code> environment variable.<\/p>\n<h3 id=\"where-is-the-kubeconfig-file-located\">Where is the Kubeconfig file located?<\/h3>\n<p>All the kubeconfig files are located in the .kube directory in the user home directory. That is <strong><code>$HOME\/.kube\/config<\/code><\/strong><\/p>\n<h3 id=\"how-to-manage-multiple-kubeconfig-files\">How to manage multiple Kubeconfig files?<\/h3>\n<p>You can store all the kubeconfig files in <code>$HOME\/.kube<\/code> directory. You need to change the cluster context to connect to a specific cluster.<\/p>\n<h3 id=\"how-to-create-a-kubeconfig-file\">How to create a Kubeconfig file?<\/h3>\n<p>To create a Kubeconfig file, you need to have the cluster endpoint details, cluster CA certificate, and authentication token. Then you need to create a Kubernetes YAML object of type config with all the cluster details.<\/p>\n<h3 id=\"how-to-use-proxy-with-kubeconfig\">How to use Proxy with Kubeconfig?<\/h3>\n<p>If you are behind a corporate proxy, you can use <code><strong>proxy-url<\/strong>: https:\/\/proxy.host:port<\/code> in your Kubeconfig file to connect to the cluster.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>In this blog, we learned different ways to connect to the Kubernetes cluster using a custom Kubeconfig file.<\/p>\n<p>If you are learning Kubernetes, check out the comprehensive list of <a href=\"https:\/\/devopscube.com\/kubernetes-tutorials-beginners\/\">kubernetes tutorials for beginners<\/a><\/p>\n<p>If you are interested in Kubernetes certification check out the <a href=\"https:\/\/devopscube.com\/best-kubernetes-certifications\/\" rel=\"noreferrer noopener\">best kubernetes certifications<\/a> guide that helps you choose the right Kubernetes certification based on your domain competencies.<\/p>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/kubernetes-kubeconfig-file\/\" target=\"_blank\" rel=\"noopener noreferrer\">Kubeconfig File Explained (Examples, Usage and Configuration) \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/kubernetes-kubeconfig-file\/<\/p>\n","protected":false},"author":1,"featured_media":565,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-564","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/564","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=564"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/564\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/565"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}