K9s Dashboard Example
Download the YAML configuration file for the deployment example
Install K9s
Windows (with Chocolatey):
macOS (with Brew):
Linux:
See the K9s installation guide for Linux instructions.
Create Deployment
Creates the deployment from the YAML file and starts the pods.
Launch K9s Dashboard
Launches the K9s dashboard in a new terminal. Watch what's happening in K9s as the pods are created.
Delete a Pod
In K9s, select one of the pods and delete it by typing Ctrl-k. You'll notice that the pod will be replaced almost immediately due to the deployment's self-healing capability.
Cleanup
Deletes all resources defined in the YAML configuration file.
About K9s
K9s is a terminal-based UI to interact with your Kubernetes clusters. It aims to simplify navigating, observing, and managing your applications in K8s.
Website: https://k9scli.io/
YAML Configuration File
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-dep
namespace: default
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
selector:
matchLabels:
app: hello-dep
template:
metadata:
labels:
app: hello-dep
spec:
containers:
- image: gcr.io/google-samples/hello-app:1.0
imagePullPolicy: Always
name: hello-dep
ports:
- containerPort: 8080
YAML Configuration Explanation:
Deployment Structure:
- apiVersion: apps/v1 → Specifies the Kubernetes API version for Deployment resources
- kind: Deployment → Defines this as a Deployment resource
- metadata.name: hello-dep → Names the deployment "hello-dep"
- namespace: default → Places the deployment in the default namespace
Deployment Spec:
- replicas: 3 → Maintains 3 identical pod instances running
- strategy.type: RollingUpdate → Uses rolling update strategy for deployments
- rollingUpdate.maxSurge: 1 → Allows 1 extra pod during updates
- rollingUpdate.maxUnavailable: 1 → Allows 1 pod to be unavailable during updates
- selector.matchLabels.app: hello-dep → Selects pods with label "app: hello-dep"
Pod Template:
- template.metadata.labels.app: hello-dep → Labels the pods with "app: hello-dep"
- containers → Defines the container specifications
- image: gcr.io/google-samples/hello-app:1.0 → Uses the hello-app sample image
- imagePullPolicy: Always → Always pulls the image when starting a pod
- name: hello-dep → Names the container "hello-dep"
- containerPort: 8080 → Exposes port 8080 on the container
How It Works:
This deployment creates and maintains 3 replicas of a pod running the hello-app container. The RollingUpdate strategy ensures zero-downtime deployments by gradually replacing old pods with new ones. When you delete a pod using K9s, the deployment controller immediately detects the missing pod and creates a new one to maintain the desired state of 3 replicas.