Course recordings on DaDesktop for Training platform
Visit NobleProg websites for related course
Visit outline: Kubernetes from Basic to Advanced (Course code: kubernetes)
Categories: Docker · Kubernetes
Summary
Overview
This course module provides a comprehensive introduction to Kubernetes command-line tools (primarily kubectl) and core Kubernetes components. It covers the structure and usage of kubectl commands, configuration management via kubeconfig, certificate validation, and the foundational resource types including namespaces, pods, deployments, replica sets, stateful sets, and daemon sets. The session includes hands-on demonstrations of creating, labeling, and deleting namespaces, deploying pods via YAML manifests, and troubleshooting common YAML syntax errors. The content is designed to build foundational operational skills for managing Kubernetes clusters.
Topic (Timeline)
1. Kubernetes CLI Tools and kubectl Configuration [00:00:03 - 00:07:51]
- Introduces
kubectlas the primary CLI tool for interacting with the Kubernetes control plane. - Explains that
kubectlreads configuration from~/.kube/configby default, but can use alternative paths via theKUBECONFIGenvironment variable. - Clarifies version compatibility:
kubectlsupports versions within one minor version of the API server (e.g., server 1.34 supports client versions 1.33–1.35). - Details
kubectlcommand syntax:kubectl <command> <type> <name> <flags>, with examples of commands (create,get,describe,delete,apply,exec,logs) and resource types (pods,nodes,services/svc,deployments). - Describes output format flags:
-o json,-o yaml,-o wide,-o jsonpath. - Explains that
kubeconfigfiles can be descriptively named (e.g.,kconfig.yml) and stored in custom directories, not just~/.kube/config. - Demonstrates
minikubeauto-exporting thekubeconfigand how to unset it withunset KUBECONFIG. - Covers
kubectlplugins via thekrewrepository, noting that many are community-maintained and vary in quality. - Walks through inspecting client certificate validity using
openssl x509 -in client.crt -text -noout, including checkingNot Afterdate and signature algorithm (e.g., SHA256WithRSA). - Shows how to view
kubeconfigin JSON format usingkubectl config view -o json. - Demonstrates removing a user (e.g.,
minikube) from the config usingkubectl config delete-user.
2. Kubernetes Core Components: Namespaces and Resource Isolation [00:07:51 - 00:11:44]
- Defines namespaces as logical partitions for isolating resources within a cluster; resource names must be unique within a namespace.
- Recommends avoiding the
defaultnamespace in production; only thekubernetesservice should reside there. - Identifies
kube-systemas the namespace for control plane components. - Provides real-world namespace examples:
gitlab-minio,loki-minio,minio-operatorfor separating application components. - Explains that namespaces span nodes (visualized with dashed lines) and enable resource constraints:
- Default CPU/memory requests and limits
- Minimum/maximum CPU/memory ranges
- Total resource quotas
- Pod count limits
- Notes that deleting a namespace removes all contained resources — useful for testing, dangerous in production.
- States that namespaces can be labeled like other resources, enabling cross-namespace service access via features like Gateway API.
3. Kubernetes Core Components: Pods, Deployments, StatefulSets, DaemonSets, and Probes [00:11:44 - 00:17:33]
- Defines a pod as the smallest deployable unit, consisting of one or more containers (e.g., sidecars).
- Explains pod labels as key-value pairs; keys may have a prefix (e.g.,
app.kubernetes.io/name), or be private (no prefix). - Describes deployments as stateless workload controllers that manage replica sets; deployments use
spec.selectorto match pods via labels. - Notes that replica sets append a unique hash to pod names on creation/restart.
- Introduces stateful sets for stateful applications: pods retain stable network identities (e.g.,
statefulset-0,statefulset-1) and persistent storage. - Emphasizes that stateful sets require scaling to 0 before deletion to avoid orphaned resources; Helm uninstall may not delete them if not scaled down.
- Explains that stateful sets use headless services (DNS-based, not ClusterIP), which can cause integration issues if misconfigured by upstream charts.
- Describes daemon sets: run one pod per node (or selected nodes), used for CNI agents (e.g., Cilium), logging, or monitoring.
- Explains liveness, readiness, and startup probes:
- Liveness: restarts container if failing
- Readiness: removes pod from service endpoints if failing
- Startup: delays liveness/readiness checks until app is ready (for slow-starting apps)
- Notes that probes can share endpoints (e.g.,
/healthz) and warns against misconfigurations that cause cascading failures.
4. Hands-On: Namespace and Pod Management with YAML [00:17:33 - 00:23:53]
- Guides creation of a namespace
app-ausingkubectl create ns app-a. - Demonstrates labeling a namespace:
kubectl label ns app-a environment=develop. - Shows deletion of namespace:
kubectl delete ns app-a(deletes all contained resources). - Walks through creating a pod manifest (
pod-deployment.yaml) usingvim, emphasizing YAML syntax:- Correct indentation (2 spaces)
- Proper alignment of
image,imagePullPolicyunderspec.containers - Hyphen (
-) must be directly undercincontainers
- Highlights common YAML errors: misalignment causes
kubectl applyto fail silently or with vague errors. - Demonstrates that applying a manifest to a non-existent namespace results in “namespace not found” error.
- Shows re-creating the namespace and re-applying the manifest to successfully deploy the pod.
- Confirms pod creation with
kubectl get pods -n app-a. - Deletes the namespace again to clean up, confirming all resources (including the pod) are removed.
- Concludes with a note that next session will cover replica sets.
Appendix
Key Principles
- kubectl Version Compatibility: Always ensure
kubectlversion is within ±1 minor version of the API server. - YAML Syntax: Indentation and alignment are critical; one misaligned line breaks the manifest. Use linters or validate with
kubectl apply --dry-run=client. - Namespaces: Use for environment isolation (dev/stage/prod) and resource quotas. Never use
defaultin production for user workloads. - StatefulSets: Always scale to 0 before deletion. Do not rely on Helm uninstall alone.
- Probes: Use
startupProbefor slow-starting apps; avoid identical endpoints for liveness/readiness if app behavior differs during startup.
Tools Used
kubectl— Primary CLIminikube— Local cluster for testingopenssl— Certificate inspectionvim— YAML file editingKUBECONFIG— Environment variable for config path overridekrew— Plugin manager forkubectl
Common Pitfalls
- Misaligned YAML in pod manifests (e.g.,
imagenot undercontainers) - Forgetting to create namespace before applying manifest
- Assuming Helm uninstall removes StatefulSet resources
- Misconfiguring headless services in StatefulSet charts
- Using
kubectl delete nsin production without verifying contents
Practice Suggestions
- Manually type 3–5 small pod manifests from scratch to internalize YAML structure.
- Use
kubectl config view -o jsonto explore your kubeconfig structure. - Create a namespace, label it, and delete it — repeat with different names.
- Inspect a
minikubeclient certificate withopenssland note its expiration. - Try applying a malformed YAML file and interpret the error message.