You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取Kubernetes集群的admin.conf配置文件?

How to Download the admin.conf File from Your Kubernetes Master Node

Hey there! Since you're new to Kubernetes and already have access to your local clusters via the browser, grabbing the admin.conf file from the master node is straightforward—here are a couple of common methods depending on your setup:

Method 1: SSH into the Master Node (Most Common)

If you have SSH access to your master node (typical for local clusters), follow these steps:

  • First, connect to the master node using SSH:
    ssh your-username@master-node-ip-address
    
    Replace your-username with the actual username for your master node, and master-node-ip-address with the node's IP (e.g., 192.168.1.100).
  • The admin.conf file lives in the default Kubernetes config directory. Verify its location with:
    ls /etc/kubernetes/
    
  • Now, download the file to your local machine. Run this from your local terminal (not the SSH session):
    scp your-username@master-node-ip-address:/etc/kubernetes/admin.conf ~/.kube/config
    
    This copies the file directly to kubectl's default config location, so you can start using kubectl right away. If you want to save it to a specific folder instead, replace ~/.kube/config with your desired local path (e.g., ~/Downloads/admin.conf).

Method 2: Using the Kubernetes Browser Dashboard

If you only have access via the browser-based Dashboard, use this workaround to access the master node's file system:

  1. Create a temporary Pod that mounts the master node's /etc/kubernetes directory. Use the Dashboard's "Create" feature to apply this YAML:
    apiVersion: v1
    kind: Pod
    metadata:
      name: temp-config-access
    spec:
      containers:
      - name: busybox
        image: busybox:1.36
        command: ["sleep", "3600"] # Keeps the Pod running for an hour
        volumeMounts:
        - name: k8s-config-dir
          mountPath: /etc/kubernetes
      volumes:
      - name: k8s-config-dir
        hostPath:
          path: /etc/kubernetes
          type: Directory
    
  2. Once the Pod is running, open its terminal via the Dashboard. Navigate to the mounted directory:
    cd /etc/kubernetes
    
  3. View the contents of admin.conf with:
    cat admin.conf
    
  4. Copy the entire output text, then create a new file on your local machine (name it admin.conf or config) and paste the content into it.

Post-Download Setup

After getting the admin.conf file:

  • If you saved it to ~/.kube/config, you can start using kubectl immediately.
  • If you saved it elsewhere, tell kubectl where to find it by setting the environment variable:
    export KUBECONFIG=/path/to/your/admin.conf
    
  • Important note: The admin.conf file has full cluster admin permissions—keep it secure and don't share it with untrusted parties.

内容的提问来源于stack exchange,提问作者JDoe6213981

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:58:00