DEV Community

onieio
onieio

Posted on

Kubernetes Basics: Understanding Key Resources

Static Pods

Overview:
Static pods are Kubernetes pods that are managed directly by the kubelet on a node. They are not part of the Kubernetes control plane, making them suitable for running system-level daemons or essential services on individual nodes.

Usage:

Create a Static Pod:

  • Write a pod manifest file.
  • Place the file in the kubelet's specified directory (e.g., /etc/kubernetes/manifests).
  • Restart the kubelet to start the static pod.
sudo systemctl restart kubelet
Enter fullscreen mode Exit fullscreen mode

Check the status of the static pod using kubectl or kubelet logs.

kubectl get pods
kubectl describe pod my-static-pod
Enter fullscreen mode Exit fullscreen mode

Cleanup:

Delete the manifest file and restart the kubelet.

sudo rm /etc/kubernetes/manifests/my-static-pod.yaml
sudo systemctl restart kubelet
Enter fullscreen mode Exit fullscreen mode

Pods

Overview:
Pods are the smallest deployable units in Kubernetes. They represent one or more containers that share storage, network, and specifications.

Usage:

Create a Pod:

Write a pod manifest file (YAML) defining containers, volumes, and metadata.
Apply the manifest using kubectl.

kubectl apply -f my-pod.yaml
Enter fullscreen mode Exit fullscreen mode

Monitor Pod:

Check the status of the pod.

kubectl get pods
kubectl describe pod my-pod
Enter fullscreen mode Exit fullscreen mode

Update Pod:

Modify the manifest file and apply the changes.

kubectl apply -f my-updated-pod.yaml
Enter fullscreen mode Exit fullscreen mode

Deployments

Overview:
Deployments provide a declarative way to manage pod replicas, enabling easy updates and rollbacks.

Usage:

Create a Deployment:

Write a deployment manifest file specifying the desired state.
Apply the manifest using kubectl.

kubectl apply -f my-deployment.yaml
Enter fullscreen mode Exit fullscreen mode

Scale Deployment:

Update the replica count in the deployment manifest.

kubectl scale deployment my-deployment --replicas=3
Enter fullscreen mode Exit fullscreen mode

Update Deployment:

Modify the container image or other specifications in the deployment manifest.

kubectl apply -f my-updated-deployment.yaml
Enter fullscreen mode Exit fullscreen mode

StatefulSets

Overview:
StatefulSets manage the deployment and scaling of stateful applications, maintaining stable network identities and storage.

Usage:
Create a StatefulSet:

Write a StatefulSet manifest file specifying pod templates and persistent volume claims.
Apply the manifest using kubectl.

kubectl apply -f my-statefulset.yaml

Enter fullscreen mode Exit fullscreen mode

Scale StatefulSet:

Update the replica count in the StatefulSet manifest.

kubectl scale statefulset my-statefulset --replicas=3

Enter fullscreen mode Exit fullscreen mode

Update StatefulSet:

Modify the pod template or other specifications in the StatefulSet manifest.

kubectl apply -f my-updated-statefulset.yaml
Enter fullscreen mode Exit fullscreen mode

DaemonSets

Overview:
DaemonSets ensure that a copy of a pod runs on every node in the cluster, typically for system daemons or logging agents.

Usage:

Create a DaemonSet:

Write a DaemonSet manifest file specifying pod templates.
Apply the manifest using kubectl.

kubectl apply -f my-daemonset.yaml
Enter fullscreen mode Exit fullscreen mode

Update DaemonSet:

Modify the pod template or other specifications in the DaemonSet manifest.

kubectl apply -f my-updated-daemonset.yaml
Enter fullscreen mode Exit fullscreen mode

Monitor DaemonSet:

Check the status of the DaemonSet and the pods on each node.

kubectl get daemonset
kubectl get pods -l app=my-daemon
Enter fullscreen mode Exit fullscreen mode

This document provides a basic understanding of key Kubernetes resources and commands, including static pods, pods, deployments, StatefulSets, and DaemonSets. Each section includes an overview, usage examples, and common operations.

Top comments (0)