LinuxCommandLibrary

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

List resources.
describe TYPE NAME
Show resource details.
apply -f FILE
Apply configuration.
delete TYPE NAME
Delete resource.
logs POD
Show pod logs.
exec POD
Execute in container.
-n NAMESPACE
Target namespace.
--help
Display help information.

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)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community