CFN Cloud
Cloud Future New Life
en zh
2025-10-01 · 0 views

Kubernetes Basics

Link core objects, controllers, and workflows with the fewest concepts.

Kubernetes is simple at its core: you declare the desired state in YAML, and controllers continuously reconcile reality to match it.

Four core objects

  • Pod: the smallest scheduling unit
  • Deployment: manages replicas and rolling updates
  • Service: stable access point
  • Namespace: logical isolation boundary

Declarative model

  • You describe what you want
  • Controllers decide how to make it happen
  • Reapplying the same YAML is safe and idempotent

Minimal Deployment example

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
spec:
  replicas: 2
  selector:
    matchLabels:
      app: hello
  template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
        - name: web
          image: nginx:1.25
          ports:
            - containerPort: 80

Common commands

  • kubectl apply -f hello.yaml
  • kubectl get deploy,pods
  • kubectl describe deploy hello
  • kubectl logs deploy/hello

Pitfalls

  • Labels and selectors do not match
  • Updating YAML without checking rollout status
  • Treating Service as a full reverse proxy

Practical notes

  • Start with a quick inventory: kubectl get nodes, kubectl get pods -A, and kubectl get events -A.
  • Compare desired vs. observed state; kubectl describe usually explains drift or failed controllers.
  • Keep names, labels, and selectors consistent so Services and controllers can find Pods.

Quick checklist

  • The resource matches the intent you described in YAML.
  • Namespaces, RBAC, and images are correct for the target environment.
  • Health checks and logs are in place before promotion.

References