Skip to content

kubectl apply

Description

kubectl apply creates or updates Kubernetes resources using configuration files.

It compares the configuration defined in a file with the current cluster state and applies the necessary changes.

Syntax

kubectl apply -f [file]

Examples

Apply a Configuration File

kubectl apply -f deployment.yaml

Apply a Directory of Manifests

kubectl apply -f manifests/

Apply Resources from a URL

kubectl apply -f https://example.com/deployment.yaml

Example Manifest

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 2


Typical Use Cases

  • deploying applications
  • updating configurations
  • managing infrastructure as code

  • kubectl get
  • kubectl describe