Skip to content

Kubernetes kubectl API

kubectl command-line tool for deploying and inspecting applications on a Kubernetes cluster.

1 class · 6 methods

Commands

6 methods

Subcommands 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

NameTypeDescription
filestringManifest file path or URL; '-' reads from stdin.
namespacestringOptional target namespace.

Returns

void

Example

kubernetes
kubectl apply -f deployment.yaml -n production
kubectl get type [name] [-o format] [-n namespace]

Lists one or more resources with basic status information.

Parameters

NameTypeDescription
typestringResource type, e.g. pods, svc, deployments.
namestringOptional resource name.
formatstringOutput format: wide, yaml, json, jsonpath.

Returns

void

Example

kubernetes
kubectl get pods -o wide -n kube-system
kubectl describe type name [-n namespace]

Shows detailed, human-readable information about a specific resource including events.

Parameters

NameTypeDescription
typestringResource type.
namestringResource name.

Returns

void

Example

kubernetes
kubectl describe pod nginx-6799fc88d8-abc12
kubectl delete (-f file | type name) [--grace-period=0]

Removes resources by file, name, label selector or all.

Parameters

NameTypeDescription
filestringManifest path declaring resources to delete.
typestringResource type when deleting by name.
namestringResource name when deleting by name.

Returns

void

Example

kubernetes
kubectl delete pod buggy-pod --grace-period=0 --force
kubectl logs [-f] pod [-c container] [-n namespace]

Prints container logs. Follows logs with -f; selects a container when a pod has several.

Parameters

NameTypeDescription
podstringPod name.
containerstringContainer name inside the pod.

Returns

void

Example

kubernetes
kubectl logs -f api-7d8-xyz -c app
kubectl exec [-it] pod -- command [args...]

Executes a command inside a container in a pod.

Parameters

NameTypeDescription
podstringPod name.
commandstringCommand to execute.

Returns

void

Example

kubernetes
kubectl exec -it web-pod -- /bin/sh