日期:2023-08-04  浏览次数:278 次

官方参考安装教程:http://kubernetes.io/docs/tasks/tools/install-kubectl-windows/

实际安装教程:

配置Windows环境变量Path:C:\Program Files\kubectl

 

C:\Users\Administrator>kubectl
kubectl controls the Kubernetes cluster manager.

 Find more information at: http://kubernetes.io/docs/reference/kubectl/

Basic Commands (Beginner):
  create          Create a resource from a file or from stdin
  expose          Take a replication controller, service, deployment or pod and expose it as a new Kubernetes service
  run             Run a particular image on the cluster
  set             Set specific features on objects

Basic Commands (Intermediate):
  explain         Get documentation for a resource
  get             Display one or many resources
  edit            Edit a resource on the server
  delete          Delete resources by file names, stdin, resources and names, or by resources and label selector

Deploy Commands:
  rollout         Manage the rollout of a resource
  scale           Set a new size for a deployment, replica set, or replication controller
  autoscale       Auto-scale a deployment, replica set, stateful set, or replication controller

Cluster Management Commands:
  certificate     Modify certificate resources.
  cluster-info    Display cluster information
  top             Display resource (CPU/memory) usage
  cordon          Mark node as unschedulable
  uncordon        Mark node as schedulable
  drain           Drain node in preparation for maintenance
  taint           Update the taints on one or more nodes

Troubleshooting and Debugging Commands:
  describe        Show details of a specific resource or group of resources
  logs            Print the logs for a container in a pod
  attach          Attach to a running container
  exec            Execute a command in a container
  port-forward    Forward one or more local ports to a pod
  proxy           Run a proxy to the Kubernetes API server
  cp              Copy files and directories to and from containers
  auth            Inspect authorization
  debug           Create debugging sessions for troubleshooting workloads and nodes
  events          List events

Advanced Commands:
  diff            Diff the live version against a would-be applied version
  apply           Apply a configuration to a resource by file name or stdin
  patch           Update fields of a resource
  replace         Replace a resource by file name or stdin
  wait            Experimental: Wait for a specific condition on one or many resources
  kustomize       Build a kustomization target from a directory or URL

Settings Commands:
  label           Update the labels on a resource
  annotate        Update the annotations on a resource
  completion      Output shell completion code for the specified shell (bash, zsh, fish, or powershell)

Other Commands:
  api-resources   Print the supported API resources on the server
  api-versions    Print the supported API versions on the server, in the form of "group/version"
  config          Modify kubeconfig files
  plugin          Provides utilities for interacting with plugins
  version         Print the client and server version information

Usage:
  kubectl [flags] [options]

Use "kubectl <command> --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all commands).

C:\Users\Administrator>kubectl version --client
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.4", GitCommit:"fa3d7990104d7c1f16943a67f11b154b71f6a132", GitTreeState:"clean", BuildDate:"2023-07-19T12:20:54Z", GoVersion:"go1.20.6", Compiler:"gc", Platform:"windows/amd64"}
Kustomize Version: v5.0.1

直接下载2个文件下来,cd 进入文件夹,运行命令

在 Windows 上安装 kubectl

在 Windows 上安装 kubectl 有以下方法:

在 Windows 上使用 curl 安装 kubectl 二进制文件

  1. 下载最新的 1.27 补丁版本: kubectl 1.27.4

    或者,如果您已curl安装,请使用以下命令:

    curl.exe -LO "http://dl.k8s.io/release/v1.27.4/bin/windows/amd64/kubectl.exe"
    

     

    注意:要查找最新的稳定版本(例如,用于脚本编写),请查看 http://dl.k8s.io/release/stable.txt
  2. 验证二进制文件(可选)

    下载kubectl校验和文件:

    curl.exe -LO "http://dl.k8s.io/v1.27.4/bin/windows/amd64/kubectl.exe.sha256"
    

    kubectl根据校验和文件验证二进制文件:

    • 使用命令提示符手动将 的CertUtil输出与下载的校验和文件进行比较:

      CertUtil -hashfile kubectl.exe SHA256
      type kubectl.exe.sha256
      
    • 使用 PowerShell 自动验证,使用-eq运算符获取TrueorFalse结果:

       $(Get-FileHash -Algorithm SHA256 .\kubectl.exe).Hash -eq $(Get-Content .\kubectl.exe.sha256)
      
  3. 将二进制文件夹附加或添加到环境变量kubectlPATH

  4. 测试以确保版本kubectl与下载的版本相同:

    kubectl version --client
    
    笔记:

    上述命令将生成一个警告:

    WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.
    

    您可以忽略此警告。kubectl您仅检查已安装的版本。

    或者使用它来详细查看版本:

    kubectl version --client --output=yaml
    
注意: 适用于 Windows 的 Docker Desktop 添加了自己的kubectl版本PATH。如果您之前安装过 Docker Desktop,则可能需要将PATH条目放在 Docker Desktop 安装程序添加的条目之前,或者删除 Docker Desktop 的kubectl.