Basic Kubernetes Overview¶
Introduction¶
This guide aims to quickly go over core Kubernetes components and help you get an overview of the ecosystem. It aims to give K8s newcomers a quick & abbreviated reference.
If you are already familiar with Kubernetes, you can easily skip this page. It contains no Juno-specific information.
This guide does not expand on each subject in close detail. For a deeper dive, the Concepts Section of the upstream documentation is an excellent resource.
If you are new to Kubernetes, a good approach would be to read through the upstream documentation and come back to this page whenever you need to quickly look a topic up.
Installing kubectl¶
kubectl is the command-line tool for interacting with Kubernetes clusters. It's your primary interface for managing applications and troubleshooting issues. For how to install it on your specific platform, refer to upstream documentation.
Useful kubectl Aliases¶
Add to your .bashrc
or .zshrc
:
alias k='kubectl'
alias kgp='kubectl get pods'
alias kgs='kubectl get svc'
alias kgd='kubectl get deployment'
alias kaf='kubectl apply -f'
alias kdel='kubectl delete'
alias klog='kubectl logs'
alias kexec='kubectl exec -it'
Basic Kubernetes Concepts¶
Understanding Kubernetes starts with grasping its fundamental building blocks. Each component serves a specific purpose in the orchestration ecosystem.
Core Components¶
graph TB
subgraph "Control Plane"
API[API Server]
ETCD[etcd]
SCH[Scheduler]
CM[Controller Manager]
end
subgraph "Worker Node"
KUB[kubelet]
KP[kube-proxy]
CR[Container Runtime]
POD1[Pod]
POD2[Pod]
end
API --> KUB
SCH --> API
CM --> API
ETCD --> API
style API stroke:#2E86AB,stroke-width:2px
style POD1 stroke:#A23B72,stroke-width:2px
style POD2 stroke:#A23B72,stroke-width:2px
Control Plane Components¶
API Server: The front door to Kubernetes. All commands (via kubectl or other clients) go through the API server. It validates and processes REST operations, updating the cluster state in etcd.
etcd: The cluster's database. A distributed key-value store that reliably stores all cluster data including configuration, state, and metadata. Think of it as Kubernetes' memory.
Scheduler: The matchmaker for pods and nodes. When you create a pod, the scheduler finds the best node to run it on based on resource requirements, constraints, and policies.
Controller Manager: The automation engine. It runs control loops that watch the cluster state and make changes to move the current state toward the desired state (e.g., ensuring the right number of pod replicas exist).
Node Components¶
kubelet: The node agent that runs on each worker node. It ensures containers are running in pods according to specifications. It's like a local supervisor for containers.
kube-proxy: The network proxy running on each node. It maintains network rules that allow pods to communicate with each other and the outside world.
Container Runtime: The software responsible for running containers (e.g., containerd, CRI-O). It pulls images and manages the container lifecycle.
Key Resources¶
Pods¶
The smallest deployable unit in Kubernetes. A pod contains one or more containers that share storage, network, and specifications.
Why Pods?: Containers in a pod share the same network namespace (IP address and ports) and can communicate via localhost. They're scheduled together and run in a shared context.
apiVersion: v1
kind: Pod
metadata:
name: example-pod
labels:
app: myapp
spec:
containers:
- name: app
image: nginx:latest
ports:
- containerPort: 80
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
Deployments¶
Manages the desired state for pods and ReplicaSets. Deployments provide declarative updates, scaling, and rollback capabilities.
Key Features:
-
Maintains desired number of pod replicas
-
Supports rolling updates with zero downtime
-
Automatic rollback on failures
-
Scaling up or down
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-deployment
spec:
replicas: 3
selector:
matchLabels:
app: example
template:
metadata:
labels:
app: example
spec:
containers:
- name: app
image: nginx:latest
ports:
- containerPort: 80
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 30
periodSeconds: 10
Services¶
Provides stable network endpoint for a set of pods. Since pods are ephemeral and get new IPs when recreated, services provide a consistent way to access them.
Service Types:
-
ClusterIP (default): Internal cluster access only
-
NodePort: Exposes service on each node's IP at a static port
-
LoadBalancer: Exposes service via cloud provider's load balancer
apiVersion: v1
kind: Service
metadata:
name: example-service
spec:
selector:
app: example
ports:
- port: 80
targetPort: 80
type: ClusterIP
ConfigMaps and Secrets¶
ConfigMaps: Store non-sensitive configuration data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or configuration files.
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
database_url: "postgres://db.example.com:5432/myapp"
log_level: "info"
Secrets: Similar to ConfigMaps but designed for sensitive data. Secrets are base64 encoded (not encrypted by default) and have restrictions on how they can be accessed.
apiVersion: v1
kind: Secret
metadata:
name: app-secret
type: Opaque
stringData:
password: "my-secret-password"
api-key: "abc123xyz789"
Namespaces¶
Namespaces provide logical isolation and organization within a cluster. They're like virtual clusters within your physical cluster.
Use Cases: - Separate environments (dev, staging, prod) - Multi-tenancy - Resource quotas and limits - Access control boundaries
# Create namespace
kubectl create namespace my-app
# List namespaces
kubectl get namespaces
# Set default namespace for current context
kubectl config set-context --current --namespace=my-app
# Run commands in specific namespace
kubectl get pods -n my-app
Labels and Selectors¶
Labels are key-value pairs attached to objects. Selectors use labels to filter and identify sets of objects.
Using selectors:
# Get all pods with label app=web
kubectl get pods -l app=web
# Get pods with multiple labels
kubectl get pods -l app=web,tier=frontend
# Get pods without a label
kubectl get pods -l '!beta'