Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

55 of kubernetes practice: configuration kubeconfig of kubectl

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

One: brief introduction

When using the kubectl command line, you first need to configure the Kubeconfig file, which is used to configure how to access Kubernetes API, including Kubernetes API Server URL and authentication information, and you can set different contexts to quickly switch access environments.

Two: example of Kubeconfig file

Click (here) to collapse or open

ApiVersion: v1

Kind: Config

Clusters:

-cluster:

Certificate-authority: / etc/kubernetes/ca.crt

Server: https://kube-master:6443

Name: k8s

Users:

-name: admin

User:

-- client-certificate=/etc/kubernetes/ssl/admin.pem

-- embed-certs=true

-- client-key=/etc/kubernetes/ssl/admin-key.pem

Contexts:

-context:

Cluster: k8s

User: admin

Namespace: default

Name: default

Current-context: default

Preferences: {} 1.cluster: set the access URL and related properties of kubernetes api server

2.users: sets authentication information for accessing Kubernetes API Server

3.contexts: setting the kubelet execution context

4.current-context: sets the current context of kubelet execution

5.perferences: setting other properties of kubelet

Three: Kubectl config command

The Kubeconfig file can be edited manually or queried and set up through the kubectl config command.

1.kubectl config view: viewing Kubeconfig fil

2.kubectl config set-cluster: set the clusters of kubeconfig

Click (here) to collapse or open

Kubectl config set-cluster kubernetes\

-- certificate-authority=/etc/kubernetes/ssl/ca.pem\

-- embed-certs=true\

-- server=$ {KUBE_APISERVER} 3.kubectl config set-credentials: sets the users of kubeconfig

Click (here) to collapse or open

Kubectl config set-credentials admin\

-- client-certificate=/etc/kubernetes/ssl/admin.pem\

-- embed-certs=true\

-- client-key=/etc/kubernetes/ssl/admin-key.pem4.kubectl config set-context: sets the contexts of Kubeconfig

Click (here) to collapse or open

Kubectl config set-context kubernetes\

-- cluster=kubernetes\

-- user=admin5.kubectl config use-context: sets the current-context of Kubeconfig

Click (here) to collapse or open

Kubectl config use-context kubernetes

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report