Skip to main content

Pod Manifests

apiVersion: v1
kind: Pod
metadata:
  name: nnappone
  namespace: learning
  labels:
    app: nnappone
spec:
  containers:
    - name: networknuts-app
      image: lovelearnlinux/webserver:v1
      ports:
        - containerPort: 80
          name: http
          protocol: TCP

Deployment Manifests

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-declarative
  annotations:
    environment: prod
    organization: sales
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest

DaemonSet Manifests

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd-logging
  labels:
    k8s-app: fluentd-logging
spec:
  selector:
    matchLabels:
      name: fluentd-elasticsearch
  template:
    metadata:
      labels:
        name: fluentd-elasticsearch
    spec:
      containers:
      - name: fluentd-elasticsearch
        image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
DaemonSets ensure all (or some) nodes run a copy of a Pod. Common use cases: logs collection, node monitoring, cluster storage daemons

StatefulSet Manifests

apiVersion: v1
kind: Service
metadata:
  name: nginx-headless
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  selector:
    matchLabels:
      app: nginx
  serviceName: "nginx-headless"
  replicas: 3
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: k8s.gcr.io/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "standard"
      resources:
        requests:
          storage: 1Gi
StatefulSets provide stable network identities and persistent storage for stateful applications like databases

Job and CronJob Manifests

apiVersion: batch/v1
kind: Job
metadata:
  name: batch-job
spec:
  template:
    metadata:
      labels:
        app: batch-job
    spec:
      restartPolicy: OnFailure
      containers:
      - name: nn-batch
        image: lovelearnlinux/batch-job
Jobs create one or more Pods and ensure a specified number complete successfully

Service Manifests

apiVersion: v1
kind: Service
metadata:
  name: nnappone-service
spec:
  selector:
    app: nnappone
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 80
ClusterIP is the default service type - accessible only within the cluster

ConfigMap and Secret Manifests

apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
  namespace: prod
data:
  database_url: "postgresql://db:5432"
  max_connections: "100"
  log_level: "info"
ConfigMaps store non-confidential configuration data as key-value pairs

Storage Manifests

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pvone-nfs
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: slow
  nfs:
    path: /foldername
    server: ip-address-nfs-server

Autoscaling Manifests

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: my-app
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: my-app
  minReplicas: 1
  maxReplicas: 5
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 66
HPA automatically scales Pods based on CPU/memory utilization or custom metrics

Resource Management

apiVersion: v1
kind: LimitRange
metadata:
  name: def-cpu-mem-limit
  namespace: dev
spec:
  limits:
  - default:
      cpu: 111m
      memory: 99Mi
    defaultRequest:
      cpu: 101m
      memory: 91Mi
    max:
      cpu: 200m
      memory: 100Mi
    min:
      cpu: 100m
      memory: 90Mi
    type: Container
How it works:
  • If Pod has no resource block → default and defaultRequest apply
  • If Pod has resource block → values must be within min and max

NetworkPolicy Manifests

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: deny-all-ingress
  namespace: default
spec:
  podSelector: {}
  policyTypes:
  - Ingress
This policy denies all incoming traffic to all Pods in the namespace by default

Access Modes Reference

Access ModeAbbreviationDescription
ReadWriteOnceRWOVolume can be mounted read-write by a single node
ReadOnlyManyROXVolume can be mounted read-only by many nodes
ReadWriteManyRWXVolume can be mounted read-write by many nodes
ReadWriteOncePodRWOPVolume can be mounted read-write by a single Pod

Common kubectl Commands

kubectl create -f manifest.yaml
kubectl apply -f manifest.yaml

Build docs developers (and LLMs) love