k8s:core:kind
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| k8s:core:kind [2026/05/31 03:06] – created phong2018 | k8s:core:kind [2026/05/31 04:07] (current) – [Here's the relationship diagram.] phong2018 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== kind ====== | + | ====== |
| - | kind defines **what type of Kubernetes object you want to create**. | + | ===== Overview ===== |
| - | --- | + | In Kubernetes, every resource manifest (written in YAML or JSON) must declare four top-level fields: |
| - | ===== Examples ===== | + | <code yaml> |
| + | apiVersion: apps/v1 | ||
| + | kind: Deployment | ||
| + | metadata: | ||
| + | name: my-app | ||
| + | spec: | ||
| + | ... | ||
| + | </ | ||
| - | | + | The '' |
| - | | + | |
| - | | + | |
| - | | + | |
| - | * Secret | + | |
| - | * Namespace | + | |
| - | --- | + | ---- |
| - | ===== Example | + | ===== Core Resource Kinds ===== |
| + | ==== 1. Pod ==== | ||
| + | The **smallest deployable unit** in Kubernetes. A Pod wraps one or more containers that share network and storage. | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: v1 | ||
| + | kind: Pod | ||
| + | metadata: | ||
| + | name: nginx-pod | ||
| + | labels: | ||
| + | app: nginx | ||
| + | spec: | ||
| + | containers: | ||
| + | - name: nginx | ||
| + | image: nginx:1.25 | ||
| + | ports: | ||
| + | - containerPort: | ||
| + | </ | ||
| + | |||
| + | ^ Field ^ Description | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | |||
| + | > **Note:** Pods are rarely created directly. Use Deployments or StatefulSets instead for resilience. | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== 2. Deployment ==== | ||
| + | |||
| + | Manages a **ReplicaSet** to ensure a specified number of Pod replicas are running at all times. Supports rolling updates and rollbacks. | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: apps/v1 | ||
| kind: Deployment | kind: Deployment | ||
| + | metadata: | ||
| + | name: web-app | ||
| + | namespace: default | ||
| + | spec: | ||
| + | replicas: 3 | ||
| + | selector: | ||
| + | matchLabels: | ||
| + | app: web-app | ||
| + | template: | ||
| + | metadata: | ||
| + | labels: | ||
| + | app: web-app | ||
| + | spec: | ||
| + | containers: | ||
| + | - name: web | ||
| + | image: nginx:1.25 | ||
| + | ports: | ||
| + | - containerPort: | ||
| + | </ | ||
| + | |||
| + | ^ Field ^ Description | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== 3. Service ==== | ||
| + | |||
| + | Exposes a set of Pods as a **stable network endpoint**. Handles load balancing across all matching Pods. | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: v1 | ||
| + | kind: Service | ||
| + | metadata: | ||
| + | name: web-service | ||
| + | spec: | ||
| + | selector: | ||
| + | app: web-app | ||
| + | ports: | ||
| + | - protocol: TCP | ||
| + | port: 80 | ||
| + | targetPort: 80 | ||
| + | type: ClusterIP | ||
| + | </ | ||
| + | |||
| + | ^ Service Type ^ Description | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== 4. ConfigMap ==== | ||
| + | |||
| + | Stores **non-sensitive configuration** as key-value pairs, decoupling config from container images. | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: v1 | ||
| + | kind: ConfigMap | ||
| + | metadata: | ||
| + | name: app-config | ||
| + | data: | ||
| + | APP_ENV: production | ||
| + | APP_PORT: " | ||
| + | log_level: info | ||
| + | </ | ||
| + | |||
| + | Use in a Pod: | ||
| + | |||
| + | <code yaml> | ||
| + | envFrom: | ||
| + | - configMapRef: | ||
| + | name: app-config | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== 5. Secret ==== | ||
| + | |||
| + | Like ConfigMap, but for **sensitive data** (passwords, tokens, TLS certs). Values are base64-encoded. | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: v1 | ||
| + | kind: Secret | ||
| + | metadata: | ||
| + | name: db-credentials | ||
| + | type: Opaque | ||
| + | data: | ||
| + | username: YWRtaW4= | ||
| + | password: cGFzc3dvcmQ= | ||
| + | </ | ||
| + | |||
| + | > **Security note:** base64 is encoding, not encryption. Use tools like Sealed Secrets or Vault for production. | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== 6. StatefulSet ==== | ||
| + | |||
| + | Like Deployment, but designed for **stateful applications** (databases, message queues) that need: | ||
| + | * Stable, persistent network identity | ||
| + | * Ordered, graceful deployment and scaling | ||
| + | * Persistent storage per pod | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: apps/v1 | ||
| + | kind: StatefulSet | ||
| + | metadata: | ||
| + | name: mysql | ||
| + | spec: | ||
| + | serviceName: | ||
| + | replicas: 3 | ||
| + | selector: | ||
| + | matchLabels: | ||
| + | app: mysql | ||
| + | template: | ||
| + | metadata: | ||
| + | labels: | ||
| + | app: mysql | ||
| + | spec: | ||
| + | containers: | ||
| + | - name: mysql | ||
| + | image: mysql:8.0 | ||
| + | env: | ||
| + | - name: MYSQL_ROOT_PASSWORD | ||
| + | value: " | ||
| + | volumeMounts: | ||
| + | - name: data | ||
| + | mountPath: / | ||
| + | volumeClaimTemplates: | ||
| + | - metadata: | ||
| + | name: data | ||
| + | spec: | ||
| + | accessModes: | ||
| + | resources: | ||
| + | requests: | ||
| + | storage: 10Gi | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== 7. DaemonSet ==== | ||
| + | |||
| + | Ensures a **copy of a Pod runs on every node** (or selected nodes). Used for cluster-level services like log collectors, monitoring agents, or network plugins. | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: apps/v1 | ||
| + | kind: DaemonSet | ||
| + | metadata: | ||
| + | name: fluentd | ||
| + | spec: | ||
| + | selector: | ||
| + | matchLabels: | ||
| + | name: fluentd | ||
| + | template: | ||
| + | metadata: | ||
| + | labels: | ||
| + | name: fluentd | ||
| + | spec: | ||
| + | containers: | ||
| + | - name: fluentd | ||
| + | image: fluent/ | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== 8. Job ==== | ||
| + | |||
| + | Runs a **one-off task** to completion. Kubernetes ensures the Pod runs successfully at least once. | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: batch/v1 | ||
| + | kind: Job | ||
| + | metadata: | ||
| + | name: db-migration | ||
| + | spec: | ||
| + | template: | ||
| + | spec: | ||
| + | containers: | ||
| + | - name: migrate | ||
| + | image: myapp: | ||
| + | command: [" | ||
| + | restartPolicy: | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== 9. CronJob ==== | ||
| + | |||
| + | Runs Jobs on a **scheduled (cron) basis**. | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: batch/v1 | ||
| + | kind: CronJob | ||
| + | metadata: | ||
| + | name: backup-job | ||
| + | spec: | ||
| + | schedule: "0 2 * * *" | ||
| + | jobTemplate: | ||
| + | spec: | ||
| + | template: | ||
| + | spec: | ||
| + | containers: | ||
| + | - name: backup | ||
| + | image: backup-tool: | ||
| + | command: ["/ | ||
| + | restartPolicy: | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== 10. Namespace ==== | ||
| + | |||
| + | Creates a **virtual cluster** within a Kubernetes cluster, providing isolation between teams or environments. | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: v1 | ||
| + | kind: Namespace | ||
| + | metadata: | ||
| + | name: staging | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== 11. PersistentVolumeClaim (PVC) ==== | ||
| + | |||
| + | Requests **persistent storage** from the cluster for a Pod. | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: v1 | ||
| + | kind: PersistentVolumeClaim | ||
| + | metadata: | ||
| + | name: my-storage | ||
| + | spec: | ||
| + | accessModes: | ||
| + | - ReadWriteOnce | ||
| + | resources: | ||
| + | requests: | ||
| + | storage: 5Gi | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== 12. Ingress ==== | ||
| + | |||
| + | Manages **external HTTP/HTTPS access** to services, routing rules, TLS termination. | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: networking.k8s.io/ | ||
| + | kind: Ingress | ||
| + | metadata: | ||
| + | name: web-ingress | ||
| + | annotations: | ||
| + | nginx.ingress.kubernetes.io/ | ||
| + | spec: | ||
| + | rules: | ||
| + | - host: myapp.example.com | ||
| + | http: | ||
| + | paths: | ||
| + | - path: / | ||
| + | pathType: Prefix | ||
| + | backend: | ||
| + | service: | ||
| + | name: web-service | ||
| + | port: | ||
| + | number: 80 | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== Summary Table ===== | ||
| + | |||
| + | ^ Kind ^ API Version | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== How '' | ||
| + | |||
| + | The '' | ||
| + | |||
| + | ^ apiVersion | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== Here's the relationship diagram. ===== | ||
| + | Hierarchy flows top-down: | ||
| + | |||
| + | Deployment → ReplicaSet → Pod (Deployment manages replicas, which manage pods) | ||
| + | |||
| + | StatefulSet and DaemonSet go straight to their own Pods | ||
| + | |||
| + | CronJob → Job (CronJob triggers Jobs on a schedule) | ||
| + | |||
| + | Networking routes traffic inward: | ||
| + | |||
| + | Ingress → Service → Pod (external HTTP traffic funneled down to running containers) | ||
| + | NetworkPolicy applies traffic rules at the Pod level | ||
| - | --- | + | Config and Storage are mounted into Pods: |
| - | ===== Real-world meaning ===== | + | ConfigMap and Secret are injected as env vars or volume mounts (dashed lines) |
| - | kind = "what am I building?" | + | PVC (PersistentVolumeClaim) binds to a PV (PersistentVolume) and mounts into Pods |
| - | * Pod → run container | + | Everything lives inside a `Namespace for isolation. |
| - | * Deployment → manage pods | + | |
| - | * Service → expose pods | + | |
| - | --- | + | {{ : |
| - | ===== Key idea ===== | + | ===== See Also ===== |
| - | kind tells Kubernetes | + | * [[https:// |
| + | * [[https:// | ||
| + | * '' | ||
k8s/core/kind.1780196814.txt.gz · Last modified: by phong2018
