LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

kubectl

kubernetes command-line tool

TLDR

Get resources
$ kubectl get [pods|deployments|services|nodes]
copy
Describe resource
$ kubectl describe [pod] [name]
copy
Apply manifest
$ kubectl apply -f [manifest.yaml]
copy
Delete resource
$ kubectl delete [pod] [name]
copy
View logs
$ kubectl logs [pod-name]
copy
Execute in pod
$ kubectl exec -it [pod-name] -- [/bin/bash]
copy
Port forward
$ kubectl port-forward [pod-name] [8080:80]
copy

SYNOPSIS

kubectl [options] command [type] [name] [flags]

DESCRIPTION

kubectl is the official command-line interface for Kubernetes, used to communicate with the cluster's API server to manage and inspect resources. It supports the full lifecycle of Kubernetes objects, including creating, reading, updating, and deleting resources such as pods, deployments, services, configmaps, and more through declarative manifests or imperative commands.The tool reads connection details from a kubeconfig file, which defines clusters, users, and contexts that determine which cluster and namespace kubectl targets. Beyond basic resource management, kubectl provides capabilities for debugging with log retrieval and exec sessions, scaling workloads, rolling out updates, port-forwarding to pods, and applying configuration changes from YAML or JSON manifests. Role-based access control (RBAC) on the cluster side governs what operations each authenticated user may perform.

PARAMETERS

get TYPE [NAME]

List resources of specified type.
describe TYPE NAME
Show detailed information about a resource.
apply -f FILE
Apply configuration from file or directory.
delete TYPE NAME
Delete a resource.
logs POD [-c container]
Show pod logs, optionally for a specific container.
exec [-it] POD -- COMMAND
Execute command in a container.
port-forward POD LOCAL:REMOTE
Forward local port to pod port.
scale TYPE/NAME --replicas=N
Scale a resource to N replicas.
create TYPE NAME
Create a resource imperatively.
edit TYPE NAME
Edit a resource in your default editor.
-n, --namespace NAMESPACE
Target namespace.
-o, --output FORMAT
Output format: json, yaml, wide, name.
-l, --selector LABEL
Filter by label selector.
--context CONTEXT
Kubeconfig context to use.
-A, --all-namespaces
List resources across all namespaces.

CAVEATS

Requires kubeconfig. Context determines cluster. RBAC affects access.

HISTORY

kubectl is the official CLI for Kubernetes, developed as the primary cluster management interface.

SEE ALSO

kubeadm(1), k9s(1), helm(1), kubectx(1)

Copied to clipboard
Kai