apply

Using apply Command

apply with YAML files

Apply can be run directly against Resource Config files or directories using -f

  1. # deployment.yaml
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: the-deployment
  6. spec:
  7. replicas: 5
  8. template:
  9. containers:
  10. - name: the-container
  11. image: registry/conatiner:latest
  1. # Apply the Resource Config
  2. kubectl apply -f deployment.yaml

This will apply the deployment file on the Kubernetes cluster. You can get the status by using a get command.

  1. # Get deployments
  2. kubectl get deployments

apply with Kustomize files

Though Apply can be run directly against Resource Config files or directories using -f, it is recommended to run Apply against a kustomization.yaml using -k. The kustomization.yaml allows users to define configuration that cuts across many Resources (e.g. namespace).

  1. # kustomization.yaml
  2. apiVersion: kustomize.config.k8s.io/v1beta1
  3. kind: Kustomization
  4. # list of Resource Config to be Applied
  5. resources:
  6. - deployment.yaml
  7. # namespace to deploy all Resources to
  8. namespace: default
  9. # labels added to all Resources
  10. commonLabels:
  11. app: example
  12. env: test
  1. # deployment.yaml
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: the-deployment
  6. spec:
  7. replicas: 5
  8. template:
  9. containers:
  10. - name: the-container
  11. image: registry/conatiner:latest

Users run Apply on directories containing kustomization.yaml files using -k or on raw ResourceConfig files using -f.

  1. # Apply the Resource Config
  2. kubectl apply -k .
  3. # View the Resources
  4. kubectl get -k .