Cloud Native 18 min read

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.

Test Development Learning Exchange
Test Development Learning Exchange
Test Development Learning Exchange
Comprehensive Guide to Installing, Configuring, and Deploying Applications on Kubernetes (K8s)

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</code>
<code>kind: ConfigMap</code>
<code>metadata:</code>
<code>  name: my-config</code>
<code>data:</code>
<code>  MYSQL_USER: root</code>
<code>  MYSQL_PASSWORD: password</code>
<code>  MYSQL_DATABASE: mydb

Create it with kubectl create -f configmap.yaml.

Job Example

apiVersion: batch/v1</code>
<code>kind: Job</code>
<code>metadata:</code>
<code>  name: my-job</code>
<code>spec:</code>
<code>  template:</code>
<code>    spec:</code>
<code>      containers:</code>
<code>      - name: my-container</code>
<code>        image: ubuntu</code>
<code>        command: ["/bin/sh", "-c", "echo Hello from the job"]</code>
<code>      restartPolicy: Never</code>
<code>      backoffLimit: 4

Apply with kubectl create -f job.yaml.

Deploying a Flask Application

apiVersion: apps/v1</code>
<code>kind: Deployment</code>
<code>metadata:</code>
<code>  name: flask-app</code>
<code>spec:</code>
<code>  replicas: 3</code>
<code>  selector:</code>
<code>    matchLabels:</code>
<code>      app: flask-app</code>
<code>  template:</code>
<code>    metadata:</code>
<code>      labels:</code>
<code>        app: flask-app</code>
<code>    spec:</code>
<code>      containers:</code>
<code>      - name: flask-app</code>
<code>        image: registry.example.com/flask-app:v1</code>
<code>        ports:</code>
<code>        - containerPort: 80

Deploy with kubectl apply -f deployment.yaml and expose via kubectl expose deployment flask-app --type=LoadBalancer.

StatefulSet Example (MySQL)

apiVersion: apps/v1</code>
<code>kind: StatefulSet</code>
<code>metadata:</code>
<code>  name: mysql</code>
<code>spec:</code>
<code>  serviceName: "mysql"</code>
<code>  replicas: 3</code>
<code>  selector:</code>
<code>    matchLabels:</code>
<code>      app: mysql</code>
<code>  template:</code>
<code>    metadata:</code>
<code>      labels:</code>
<code>        app: mysql</code>
<code>    spec:</code>
<code>      terminationGracePeriodSeconds: 10</code>
<code>      containers:</code>
<code>      - name: mysql</code>
<code>        image: mysql:5.7</code>
<code>        env:</code>
<code>        - name: MYSQL_ROOT_PASSWORD</code>
<code>          valueFrom:</code>
<code>            secretKeyRef:</code>
<code>              name: mysql-secret</code>
<code>              key: password</code>
<code>        volumeMounts:</code>
<code>        - name: data</code>
<code>          mountPath: /var/lib/mysql</code>
<code>  volumeClaimTemplates:</code>
<code>  - metadata:</code>
<code>      name: data</code>
<code>    spec:</code>
<code>      accessModes: ["ReadWriteOnce"]</code>
<code>      storageClassName: standard</code>
<code>      resources:</code>
<code>        requests:</code>
<code>          storage: 1Gi

Apply 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</code>
<code>kind: StatefulSet</code>
<code>metadata:</code>
<code>  name: redis</code>
<code>spec:</code>
<code>  serviceName: "redis"</code>
<code>  replicas: 3</code>
<code>  selector:</code>
<code>    matchLabels:</code>
<code>      app: redis</code>
<code>  template:</code>
<code>    metadata:</code>
<code>      labels:</code>
<code>        app: redis</code>
<code>    spec:</code>
<code>      terminationGracePeriodSeconds: 10</code>
<code>      containers:</code>
<code>      - name: redis</code>
<code>        image: redis:5.0-alpine</code>
<code>        ports:</code>
<code>        - containerPort: 6379</code>
<code>        volumeMounts:</code>
<code>        - name: data</code>
<code>          mountPath: /data</code>
<code>  volumeClaimTemplates:</code>
<code>  - metadata:</code>
<code>      name: data</code>
<code>    spec:</code>
<code>      accessModes: ["ReadWriteOnce"]</code>
<code>      storageClassName: standard</code>
<code>      resources:</code>
<code>        requests:</code>
<code>          storage: 1Gi

Apply with kubectl apply -f statefulset.yaml and verify with kubectl get statefulsets.

Deploying GitLab

apiVersion: apps/v1</code>
<code>kind: Deployment</code>
<code>metadata:</code>
<code>  name: gitlab</code>
<code>spec:</code>
<code>  replicas: 1</code>
<code>  selector:</code>
<code>    matchLabels:</code>
<code>      app: gitlab</code>
<code>  strategy:</code>
<code>    type: Recreate</code>
<code>  template:</code>
<code>    metadata:</code>
<code>      labels:</code>
<code>        app: gitlab</code>
<code>    spec:</code>
<code>      volumes:</code>
<code>      - name: gitlab-config</code>
<code>        persistentVolumeClaim:</code>
<code>          claimName: gitlab-config-pvc</code>
<code>      - name: gitlab-data</code>
<code>        persistentVolumeClaim:</code>
<code>          claimName: gitlab-data-pvc</code>
<code>      initContainers:</code>
<code>      - name: generate-ssh-keys</code>
<code>        image: gitlab/gitlab-ce:latest</code>
<code>        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"]</code>
<code>      containers:</code>
<code>      - name: gitlab</code>
<code>        image: gitlab/gitlab-ce:latest</code>
<code>        ports:</code>
<code>        - containerPort: 80</code>
<code>        - containerPort: 2222</code>
<code>        - containerPort: 443</code>
<code>        volumeMounts:</code>
<code>        - mountPath: "/etc/gitlab"</code>
<code>          name: gitlab-config</code>
<code>        - mountPath: "/var/opt/gitlab"</code>
<code>          name: gitlab-data

Create PVCs, Service, and Ingress as shown in the source and apply them with kubectl apply -f <file>.yaml.

Deploying Jenkins

apiVersion: apps/v1</code>
<code>kind: Deployment</code>
<code>metadata:</code>
<code>  name: jenkins-deployment</code>
<code>spec:</code>
<code>  replicas: 1</code>
<code>  selector:</code>
<code>    matchLabels:</code>
<code>      app: jenkins</code>
<code>  strategy:</code>
<code>    type: Recreate</code>
<code>  template:</code>
<code>    metadata:</code>
<code>      labels:</code>
<code>        app: jenkins</code>
<code>    spec:</code>
<code>      volumes:</code>
<code>      - name: jenkins-home</code>
<code>        emptyDir: {}</code>
<code>      containers:</code>
<code>      - name: jenkins</code>
<code>        image: jenkins/jenkins:lts</code>
<code>        ports:</code>
<code>        - containerPort: 8080</code>
<code>        volumeMounts:</code>
<code>        - mountPath: "/var/jenkins_home"</code>
<code>          name: jenkins-home
apiVersion: v1</code>
<code>kind: Service</code>
<code>metadata:</code>
<code>  name: jenkins-service</code>
<code>spec:</code>
<code>  ports:</code>
<code>  - port: 8080</code>
<code>    targetPort: 8080</code>
<code>    protocol: TCP</code>
<code>    name: jenkins</code>
<code>  selector:</code>
<code>    app: jenkins

Apply 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerYAMLk8sStatefulSetConfigMap
Test Development Learning Exchange
Written by

Test Development Learning Exchange

Test Development Learning Exchange

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.