k8s:core:kind
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| k8s:core:kind [2026/05/31 03:35] – phong2018 | k8s:core:kind [2026/05/31 04:07] (current) – [Here's the relationship diagram.] phong2018 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== kind ====== | + | ====== |
| - | The `kind` field in Kubernetes defines **what type of object you are creating**. | + | ===== Overview ===== |
| - | It tells Kubernetes: | + | In Kubernetes, every resource |
| - | * What resource | + | |
| - | * What behavior this resource has | + | |
| - | * What controller will manage it (if any) | + | |
| - | --- | + | <code yaml> |
| + | apiVersion: apps/v1 | ||
| + | kind: Deployment | ||
| + | metadata: | ||
| + | name: my-app | ||
| + | spec: | ||
| + | ... | ||
| + | </ | ||
| - | ===== 1. Core idea ===== | + | The '' |
| - | kind = **resource type in Kubernetes** | + | ---- |
| - | Think of Kubernetes as a system that supports many object types. | + | ===== Core Resource Kinds ===== |
| - | Each `kind` represents a different " | + | ==== 1. Pod ==== |
| - | --- | + | The **smallest deployable unit** in Kubernetes. A Pod wraps one or more containers that share network and storage. |
| - | ===== 2. Common kinds ===== | + | <code yaml> |
| + | apiVersion: v1 | ||
| + | kind: Pod | ||
| + | metadata: | ||
| + | name: nginx-pod | ||
| + | labels: | ||
| + | app: nginx | ||
| + | spec: | ||
| + | containers: | ||
| + | - name: nginx | ||
| + | image: nginx:1.25 | ||
| + | ports: | ||
| + | - containerPort: | ||
| + | </ | ||
| - | Kubernetes has many kinds, but the most important ones are: | + | ^ Field ^ Description |
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| - | | + | > **Note:** Pods are rarely created directly. Use Deployments or StatefulSets instead for resilience. |
| - | | + | |
| - | | + | |
| - | | + | |
| - | * ConfigMap → configuration data | + | |
| - | * Secret → sensitive data | + | |
| - | * Namespace → logical grouping | + | |
| - | --- | + | ---- |
| - | ===== 3. Example ===== | + | ==== 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 | apiVersion: apps/v1 | ||
| kind: Deployment | kind: Deployment | ||
| metadata: | metadata: | ||
| - | name: my-app | + | |
| + | namespace: default | ||
| spec: | spec: | ||
| - | replicas: 3 | + | |
| + | selector: | ||
| + | matchLabels: | ||
| + | app: web-app | ||
| + | template: | ||
| + | metadata: | ||
| + | labels: | ||
| + | app: web-app | ||
| + | spec: | ||
| + | containers: | ||
| + | - name: web | ||
| + | image: nginx: | ||
| + | ports: | ||
| + | - containerPort: | ||
| + | </ | ||
| + | ^ Field ^ Description | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| - | Here: | + | ---- |
| - | * kind: Deployment | + | |
| - | → Kubernetes creates a Deployment object | + | |
| - | --- | + | ==== 3. Service ==== |
| - | ===== 4. What happens internally ===== | + | Exposes a set of Pods as a **stable network endpoint**. Handles load balancing across all matching Pods. |
| - | When you write: | + | <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 | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| - | kind: Deployment | + | ---- |
| + | ==== 4. ConfigMap ==== | ||
| - | Kubernetes will: | + | Stores **non-sensitive configuration** as key-value pairs, decoupling config from container images. |
| - | 1. Recognize this as a Deployment object | + | <code yaml> |
| - | | + | apiVersion: v1 |
| - | | + | kind: ConfigMap |
| - | | + | metadata: |
| + | | ||
| + | data: | ||
| + | | ||
| + | | ||
| + | log_level: info | ||
| + | </ | ||
| - | Flow: | + | Use in a Pod: |
| + | <code yaml> | ||
| + | envFrom: | ||
| + | - configMapRef: | ||
| + | name: app-config | ||
| + | </ | ||
| - | Deployment | + | ---- |
| - | ↓ | + | |
| - | ReplicaSet | + | |
| - | ↓ | + | |
| - | Pods | + | |
| + | ==== 5. Secret ==== | ||
| - | --- | + | Like ConfigMap, but for **sensitive data** (passwords, tokens, TLS certs). Values are base64-encoded. |
| - | ===== 5. Why kind is important ===== | + | <code yaml> |
| + | apiVersion: v1 | ||
| + | kind: Secret | ||
| + | metadata: | ||
| + | name: db-credentials | ||
| + | type: Opaque | ||
| + | data: | ||
| + | username: YWRtaW4= # base64 of " | ||
| + | password: cGFzc3dvcmQ= # base64 of " | ||
| + | </ | ||
| - | Because Kubernetes is NOT just one system — it is a collection | + | > **Security note:** base64 |
| + | |||
| + | ---- | ||
| + | |||
| + | ==== 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 | ||
| + | |||
| + | <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 | ||
| + | </ | ||
| - | Each `kind`: | + | ---- |
| - | * Triggers a different controller | + | |
| - | * Has different behavior | + | |
| - | * Has different lifecycle rules | + | |
| - | Example: | + | ===== Summary Table ===== |
| - | * Pod → directly runs container | + | ^ Kind ^ API Version |
| - | | + | | '' |
| - | * Service → creates | + | | '' |
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| - | --- | + | ---- |
| - | ===== 6. Real-world analogy | + | ===== How '' |
| - | Think of Kubernetes like a company system: | + | The '' |
| - | * Pod → employee | + | ^ apiVersion |
| - | | + | | '' |
| - | * Service → receptionist (routes requests) | + | | '' |
| - | * ConfigMap → instruction manual | + | | '' |
| + | | '' | ||
| + | | '' | ||
| - | So: | + | ---- |
| - | kind = "what role am I creating in the system?" | + | ===== Here' |
| + | Hierarchy flows top-down: | ||
| - | --- | + | Deployment → ReplicaSet → Pod (Deployment manages replicas, which manage pods) |
| - | ===== 7. Key insight (VERY IMPORTANT) ===== | + | StatefulSet and DaemonSet go straight to their own Pods |
| - | kind is NOT just a label. | + | CronJob → Job (CronJob triggers Jobs on a schedule) |
| - | It determines: | + | Networking routes traffic inward: |
| - | * Which controller handles the object | + | |
| - | * How the object behaves | + | |
| - | * How lifecycle is managed | + | |
| - | --- | + | Ingress → Service → Pod (external HTTP traffic funneled down to running containers) |
| - | ===== 8. Simple mental model ===== | + | NetworkPolicy applies traffic rules at the Pod level |
| + | Config and Storage are mounted into Pods: | ||
| - | kind = "type of machine in Kubernetes" | + | ConfigMap and Secret are injected as env vars or volume mounts (dashed lines) |
| - | Pod → runs workload | + | PVC (PersistentVolumeClaim) binds to a PV (PersistentVolume) and mounts into Pods |
| - | Deployment → manages workload | + | |
| - | Service → exposes workload | + | |
| + | Everything lives inside a `Namespace for isolation. | ||
| - | --- | + | {{ : |
| - | ===== 9. Summary | + | ===== See Also ===== |
| - | * kind defines the type of Kubernetes | + | * [[https:// |
| - | * Each kind has a different purpose and behavior | + | * [[https:// |
| - | * Kubernetes | + | * '' |
| - | * kind drives the entire lifecycle of the resource | + | |
k8s/core/kind.1780198553.txt.gz · Last modified: by phong2018
