🗂️

Understanding Kubernetes Configuration Files

Apr 13, 2025

Kubernetes Configuration Files

Overview

  • Kubernetes configuration files are essential for creating and configuring components in a Kubernetes cluster.
  • Consists of three main parts: metadata, specification, and status.
  • Files are written in YAML, which is strict about indentations.

Components of a Configuration File

1. Metadata

  • Contains information about the component, such as its name.
  • Key-value pairs are used as labels.

2. Specification

  • Defines the desired configuration for the component.
  • Attributes vary depending on the component:
    • Deployment: includes replicas, template (which further includes metadata and specifications for pods), image, ports, etc.
    • Service: includes ports, targetPort, selector for connecting to deployments or pods.

3. Status

  • Automatically generated by Kubernetes.
  • Reflects the actual state of the component.
  • Used for self-healing by comparing with the desired state to fix discrepancies.

Key Concepts

API Version

  • Different components may require different API versions.

Self-Healing

  • Kubernetes ensures the actual state matches the desired state.
  • Example: If a deployment specifies 2 replicas, Kubernetes ensures 2 replicas are running.

Etcd

  • A key-value store used by Kubernetes to store cluster data, including status information.

YAML Structure

  • YAML format is simple but requires correct indentation.
  • Online validators can help with formatting large YAML files.

Best Practices

  • Store configuration files with application code as part of "Infrastructure as Code."
  • Can also be stored in a separate Git repository.

Working with Deployments and Services

  • Deployments manage and configure pods.
  • Services require:
    • A port where the service is accessible.
    • Target port specifying where to forward requests.
    • Connection is established through labels and selectors.

Managing Configuration Files

  • kubectl apply: To create components from configuration files.
  • kubectl delete: To remove components using configuration files.

Practical Commands

  • kubectl get pods to see running replicas.
  • kubectl describe service <service-name> to validate service endpoints.
  • kubectl get pod -o wide for extended information including IP addresses.
  • kubectl get deployment <deployment-name> -o yaml to see the full configuration including status.

Debugging and Updating

  • Automatically generated information such as timestamps and IDs should be removed if reusing configuration files.

Conclusion

  • Regularly use configuration files for deploying, updating, and managing Kubernetes components.
  • Videos are part of a series, with new content released weekly.

Additional Resources

  • Video series subscription for updates.
  • Comments section for questions and clarifications.