Comprehensive Guide to Installing, Configuring, and Deploying Applications on Kubernetes (K8s)
This article provides a step‑by‑step tutorial on preparing hardware, installing Docker, downloading and configuring Kubernetes, deploying the control plane and workloads, managing clusters, and detailed hands‑on examples for ConfigMaps, Jobs, Deployments, StatefulSets, and common applications such as Flask, MySQL, Redis, GitLab, and Jenkins, all illustrated with ready‑to‑use YAML and kubectl commands.
Kubernetes (K8s) is a container orchestration system that simplifies deploying and managing containerized applications across multiple machines.
Getting Started
Prepare at least two physical or virtual servers (minimum 2 GB RAM and 20 GB disk each) and ensure network connectivity between them.
Install Docker on each server, then download the appropriate K8s binaries for your OS and architecture.
Configure Docker networking (bridge or host mode) so that the nodes can communicate.
Deploy the K8s control plane (kubelet, API server, scheduler, controller manager, etcd) on the master node and use the graphical dashboard to monitor the cluster.
Deploy workloads by creating Docker images, pushing them to a registry, and defining Deployments in YAML.
Use the dashboard to monitor application status, adjust configurations, and perform updates.
Linux‑Based Installation Steps
1. Prepare at least two Linux hosts (one master, others workers) with identical OS and packages.
2. Install Docker on all nodes.
3. Download and extract K8s binaries on the master.
4. Create an etcd data directory and start etcd on the master.
5. Edit the K8s config file to set master and worker IPs.
6. Start K8s components (API server, scheduler, controller manager, etcd, kube‑proxy) on the master.
7. Install kubelet and kubeadm on workers and join them to the cluster.
8. Verify the cluster with kubectl get nodes .
Kubernetes Configuration Files
K8s configuration files are written in YAML or JSON and define components such as ConfigMaps and Jobs.
ConfigMap Example
apiVersion: v1
kind: ConfigMap
metadata:
name: my-config
data:
MYSQL_USER: root
MYSQL_PASSWORD: password
MYSQL_DATABASE: mydbCreate it with kubectl create -f configmap.yaml .
Job Example
apiVersion: batch/v1
kind: Job
metadata:
name: my-job
spec:
template:
spec:
containers:
- name: my-container
image: ubuntu
command: ["/bin/sh", "-c", "echo Hello from the job"]
restartPolicy: Never
backoffLimit: 4Apply with kubectl create -f job.yaml .
Deploying a Flask Application
apiVersion: apps/v1
kind: Deployment
metadata:
name: flask-app
spec:
replicas: 3
selector:
matchLabels:
app: flask-app
template:
metadata:
labels:
app: flask-app
spec:
containers:
- name: flask-app
image: registry.example.com/flask-app:v1
ports:
- containerPort: 80Deploy with kubectl apply -f deployment.yaml and expose via kubectl expose deployment flask-app --type=LoadBalancer .
StatefulSet Example (MySQL)
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql
spec:
serviceName: "mysql"
replicas: 3
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mysql
image: mysql:5.7
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secret
key: password
volumeMounts:
- name: data
mountPath: /var/lib/mysql
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: standard
resources:
requests:
storage: 1GiApply with kubectl apply -f statefulset.yaml and check status with kubectl get statefulsets and kubectl get pods -l app=mysql -o wide .
Deploying Redis (StatefulSet)
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis
spec:
serviceName: "redis"
replicas: 3
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
terminationGracePeriodSeconds: 10
containers:
- name: redis
image: redis:5.0-alpine
ports:
- containerPort: 6379
volumeMounts:
- name: data
mountPath: /data
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: standard
resources:
requests:
storage: 1GiApply with kubectl apply -f statefulset.yaml and verify with kubectl get statefulsets .
Deploying GitLab
apiVersion: apps/v1
kind: Deployment
metadata:
name: gitlab
spec:
replicas: 1
selector:
matchLabels:
app: gitlab
strategy:
type: Recreate
template:
metadata:
labels:
app: gitlab
spec:
volumes:
- name: gitlab-config
persistentVolumeClaim:
claimName: gitlab-config-pvc
- name: gitlab-data
persistentVolumeClaim:
claimName: gitlab-data-pvc
initContainers:
- name: generate-ssh-keys
image: gitlab/gitlab-ce:latest
command: ["bash", "-c", "mkdir -p /etc/gitlab && echo 'include if !-e $HOME/.ssh/id_rsa.pub' > ~/.ssh/config.d/01-authorized_keys && cat /root/.ssh/id_rsa.pub >> /etc/gitlab/initial_root_ssh_host_key && chown -R git:git /etc/gitlab"]
containers:
- name: gitlab
image: gitlab/gitlab-ce:latest
ports:
- containerPort: 80
- containerPort: 2222
- containerPort: 443
volumeMounts:
- mountPath: "/etc/gitlab"
name: gitlab-config
- mountPath: "/var/opt/gitlab"
name: gitlab-dataCreate PVCs, Service, and Ingress as shown in the source and apply them with kubectl apply -f <file>.yaml .
Deploying Jenkins
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins-deployment
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
strategy:
type: Recreate
template:
metadata:
labels:
app: jenkins
spec:
volumes:
- name: jenkins-home
emptyDir: {}
containers:
- name: jenkins
image: jenkins/jenkins:lts
ports:
- containerPort: 8080
volumeMounts:
- mountPath: "/var/jenkins_home"
name: jenkins-home apiVersion: v1
kind: Service
metadata:
name: jenkins-service
spec:
ports:
- port: 8080
targetPort: 8080
protocol: TCP
name: jenkins
selector:
app: jenkinsApply with kubectl apply -f deployment.yaml , then check pods with kubectl get pods and access the UI at the node IP.
Updating Applications
Modify the Deployment YAML (e.g., change the image tag) and apply with kubectl apply -f <file>.yaml or use kubectl rollout update deployment --image=<new-image> . Pause, resume, or undo updates with kubectl rollout pause , kubectl rollout resume , and kubectl rollout undo .
Scaling Applications
Adjust the replicas field in a Deployment or StatefulSet, then run kubectl scale deployment/<name> --replicas=3 or kubectl set replica-count deployment/<name>=3 . Similar commands work for StatefulSets and ReplicationControllers.
Test Development Learning Exchange
Test Development Learning Exchange
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.