[kubernates] 007. PV/PVC, Deployment, Service, HPA

Understanding "PV/PVC, Deployment, Service, HPA" via Application

hpyYh avatar
  • hpyYh
  • 2 min read
Photo by Gemini

PV

  • The reason for using PV/PVC is that data created inside a container is lost when the container is deleted.
  • This PV is a node-local storage that can only be mounted on k8s-master
nodeAffinity:
  required:
    nodeSelectorTerms:
      - matchExpressions:
        - {key: kubernetes.io/hostname, operator: In, values: [k8s-master]}
  • Use /root/k8s-local-volume/1231 on the k8s-master node as the storage path.
local:
  path: "/root/k8s-local-volume/1231"          //Use this path as a volume

PVC

  • Connect a Pod to a PV.
  • The resources and accessModes specified in the spec are informational and may differ from the actual underlying storage.

Deployment

  • strategy
    • Recreate: Deletes all existing Pods before creating new ones. This causes service downtime.
    • RollingUpdate: Creates new version Pods first and deletes old ones one by one after the new ones are ready.
      • maxUnavailable: The maximum number of Pods that can be unavailable during the update (e.g., at 25%, 1 out of 4 Pods is restarted at a time).
      • maxSurge: The maximum number of additional Pods that can be created above the desired replica count during the update.
  • Updates & Rollbacks: An update is triggered if any part of the template changes. Old ReplicaSets are kept to allow for quick rollbacks.

Service

  • Service Types:
    • NodePort: Connects an internal port to an external port on the node.
    • ClusterIP: For internal communication only. Access via service-name.namespace:port instead of a raw IP.
  • Service Discovery Example: http://service-name.namespace:port/version
  • Service Registry: Acts as a load balancer during deployment to distribute traffic.

HPA

  • Calculation Logic: $Current\ Pods \times (Average\ CPU / Target\ CPU) = New\ Pod\ Count$
  • Behavior : Prevention of Flapping
    • scaleUp.stabilizationWindowSeconds: Prevents rapid scaling out.
    • scaleDown.stabilizationWindowSeconds: Prevents rapid scaling in.