Resource Fields
6 methods每个 Kubernetes 清单暴露的顶层字段。
kubectl apply -f file [-n namespace]资源的 API 组和版本,如 apps/v1 或核心资源的 v1。
Parameters
| Name | Type | Description |
|---|---|---|
| file | string | Manifest file path or URL; '-' reads from stdin. |
| namespace | string | Optional target namespace. |
Returns
void
Example
kubernetes
kubectl apply -f deployment.yaml -n productionkubectl get type [name] [-o format] [-n namespace]资源类型,如 Pod、Deployment、Service、ConfigMap。
Parameters
| Name | Type | Description |
|---|---|---|
| type | string | Resource type, e.g. pods, svc, deployments. |
| name | string | Optional resource name. |
| format | string | Output format: wide, yaml, json, jsonpath. |
Returns
void
Example
kubernetes
kubectl get pods -o wide -n kube-systemkubectl describe type name [-n namespace]资源的标识和组织数据:名称、命名空间、标签、注解。
Parameters
| Name | Type | Description |
|---|---|---|
| type | string | Resource type. |
| name | string | Resource name. |
Returns
void
Example
kubernetes
kubectl describe pod nginx-6799fc88d8-abc12kubectl delete (-f file | type name) [--grace-period=0]资源的期望状态。Schema 取决于类型。
Parameters
| Name | Type | Description |
|---|---|---|
| file | string | Manifest path declaring resources to delete. |
| type | string | Resource type when deleting by name. |
| name | string | Resource name when deleting by name. |
Returns
void
Example
kubernetes
kubectl delete pod buggy-pod --grace-period=0 --forcekubectl logs [-f] pod [-c container] [-n namespace]Prints container logs. Follows logs with -f; selects a container when a pod has several.
Parameters
| Name | Type | Description |
|---|---|---|
| pod | string | Pod name. |
| container | string | Container name inside the pod. |
Returns
void
Example
kubernetes
kubectl logs -f api-7d8-xyz -c appkubectl exec [-it] pod -- command [args...]Executes a command inside a container in a pod.
Parameters
| Name | Type | Description |
|---|---|---|
| pod | string | Pod name. |
| command | string | Command to execute. |
Returns
void
Example
kubernetes
kubectl exec -it web-pod -- /bin/sh