> For the complete documentation index, see [llms.txt](https://hezhiqiang.gitbook.io/docker/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hezhiqiang.gitbook.io/docker/kubectl.md).

# Kubernetes 命令行 kubectl

[kubectl](https://github.com/kubernetes/kubernetes) 是 Kubernetes 自带的客户端，可以用它来直接操作 Kubernetes。

使用格式有两种：

```bash
kubectl [flags]
kubectl [command]
```

## get

显示一个或多个资源

## describe

显示资源详情

## create

从文件或标准输入创建资源

## update

从文件或标准输入更新资源

## delete

通过文件名、标准输入、资源名或者 label selector 删除资源

## log

输出 pod 中一个容器的日志

## rolling-update

对指定的 replication controller 执行滚动升级

## exec

在容器内部执行命令

## port-forward

将本地端口转发到Pod

## proxy

为 Kubernetes API server 启动代理服务器

## run

在集群中使用指定镜像启动容器

## expose

将 replication controller service 或 pod 暴露为新的 kubernetes service

## label

更新资源的 label

## config

修改 kubernetes 配置文件

## cluster-info

显示集群信息

## api-versions

以 "组/版本" 的格式输出服务端支持的 API 版本

## version

输出服务端和客户端的版本信息

## help

显示各个命令的帮助信息


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hezhiqiang.gitbook.io/docker/kubectl.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
