Kubernetes YAML Types:

Written by Sivaranjan

Kubernetes YAML Types:

Kubernetes YAML files are used to define the desired state of various objects and resources within a Kubernetes cluster. These files can configure a wide range of components, including workloads, networking, and configurations. Below are some of the key types of Kubernetes YAML files:

1. Pod

Defines a single instance of a running process in the cluster.

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
    - name: my-container
      image: my-image

2. Deployment

Manages a replicated application, ensuring the specified number of replicas are running.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-container
          image: my-image

3. Service

Exposes a set of Pods as a network service.

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080

4. ConfigMap

Holds configuration data in key-value pairs.

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config
data:
  configKey: configValue

5. Secret

Stores sensitive data such as passwords and OAuth tokens.

apiVersion: v1
kind: Secret
metadata:
  name: my-secret
type: Opaque
data:
  secretKey: c2VjcmV0VmFsdWU=  # base64 encoded value

6. PersistentVolume (PV)

Represents a piece of storage in the cluster.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /mnt/data

7. PersistentVolumeClaim (PVC)

Requests storage resources from a PersistentVolume.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

8. Ingress

Manages external access to the services in a cluster, typically HTTP.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
spec:
  rules:
    - host: my-app.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: my-service
                port:
                  number: 80

9. DaemonSet

Ensures that all (or some) Nodes run a copy of a Pod.

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: my-daemonset
spec:
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-container
          image: my-image

10. StatefulSet

Manages the deployment and scaling of a set of Pods with unique identities.

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: my-statefulset
spec:
  selector:
    matchLabels:
      app: my-app
  serviceName: "my-service"
  replicas: 3
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-container
          image: my-image

11. Job

Creates one or more Pods and ensures that a specified number of them successfully terminate.

apiVersion: batch/v1
kind: Job
metadata:
  name: my-job
spec:
  template:
    spec:
      containers:
        - name: my-container
          image: my-image
      restartPolicy: Never
  backoffLimit: 4

12. CronJob

Creates Jobs on a time-based schedule.

apiVersion: batch/v1
kind: CronJob
metadata:
  name: my-cronjob
spec:
  schedule: "*/5 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: my-container
              image: my-image
          restartPolicy: OnFailure

13. HorizontalPodAutoscaler (HPA)

Automatically scales the number of Pods in a deployment, replication controller, or replica set.

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: my-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: my-deployment
  minReplicas: 1
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 50

These YAML files collectively help manage and orchestrate containerized applications within a Kubernetes cluster.