Commands
6 methodsSubcommands used to create, query, update and debug Kubernetes resources.
kubectl apply -f file [-n namespace]Creates or updates resources defined in a manifest file (declarative).
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]Lists one or more resources with basic status information.
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]Shows detailed, human-readable information about a specific resource including events.
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]Removes resources by file, name, label selector or all.
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