Deployment Files

Configuration files, typically in YAML format, defining how Kubernetes resources are deployed.

In AKS, a Deployment File is a YAML file that represents a deployment, defining the number of pod replicas to be created. It acts as a blueprint for the AKS scheduler, ensuring the specified number of pods are made available on the nodes.

Characteristics of Deployment Files

  • Declarative State Configuration (DSC): Deployment files exhibit a declarative nature; you declare your requirements, and AKS orchestrates them, resolving discrepancies and errors automatically. It enhances AKS’s automation and self-healing capabilities, freeing you from constant manual interventions.
  • Manifest Files: Deployment files belong to a group of files known as manifest files, which are applied using kubectl commands, such as kubectl create or kubectl apply.
  • Flexibility and Editability: These files can be edited and changed as required to alter the configuration of the pods, facilitating scaling and resource adjustments.

Importance of Deployment Files

Utilizing deployment files is recommended as scheduling pods directly may result in the loss of AKS’s automation capabilities, making error resolution and changes cumbersome.

Example of a Deployment File

Below is an example of a deployment file for a webpage-frontend application, specifying the number of replicas, open ports, and resource requests and limits:

apiVersion: apps/v1
kind: Deployment
metadata:
name: webpage-frontend
spec:
replicas: 2
selector:
  matchLabels:
    app: webpage
template:
  metadata:
    labels:
      app: webpage
  spec:
    containers:
    - name: nginx
      image: uai3033130akstest03devacr.azurecr.io/aks-webpage:latest
   ports:
   - containerPort: 80
   resources:
     requests:
       cpu: 250m
       memory: 64Mi
     limits:
       cpu: 500m
       memory: 256Mi

To scale or modify resources, simply adjust the corresponding values and re-deploy the file using appropriate kubectl commands.

Kubectl create or kubectl apply

kubectl create and kubectl apply are two commonly used commands in Kubernetes for creating and managing resources. While they have similarities, there are important differences between them:

kubectl create:

  • Creates a new resource based on a YAML or JSON file.
  • The resource is created even if it already exists, resulting in an error.
  • If any part of the resource specification is missing, it will be set to default values defined by Kubernetes.
  • It does not update the existing resource if changes are made to the YAML or JSON file after creation.Useful for initial resource creation or creating resources with static configurations.

kubectl apply:

  • Creates a new resource or updates an existing one based on a YAML or JSON file.If the resource does not exist, it is created. If it already exists, it is updated.
  • If any part of the resource specification is missing, it retains the existing values instead of replacing them with defaults.
  • It maintains the desired state of the resource defined in the YAML or JSON file, making it suitable for managing resources over time.
  • It compares the current state of the resource with the desired state and performs necessary updates to achieve the desired state.
  • Useful for applying changes to resources or managing resources with dynamic configurations.

In summary, kubectl create is used for creating resources, while kubectl apply is used for creating or updating resources based on the desired state defined in the YAML or JSON file. kubectl apply is more suitable for managing resources over time and handling changes in configurations.

Last modified July 21, 2024: update (e2ae86c)