Skip to content

This repository contains a demonstration of deploying and managing applications using Kubernetes (k8s). It is designed to help users understand the basics of Kubernetes, including deployments, services, scaling, and other core concepts.

Notifications You must be signed in to change notification settings

JawherKl/k8s-demo

Repository files navigation

Kubernetes Demo Project

Repository Size Last Commit Issues Forks Stars

nodepost

This repository contains a demonstration of deploying and managing applications using Kubernetes (k8s). It is designed to help users understand the basics of Kubernetes, including deployments, services, scaling, and other core concepts. Whether you're new to Kubernetes or looking for a practical example to experiment with, this project provides a hands-on approach to working with k8s.


Table of Contents

  1. Overview
  2. Prerequisites
  3. Getting Started
  4. Project Structure
  5. Deploying the Application
  6. Scaling and Managing the Application
  7. Cleaning Up
  8. Contributing
  9. License

Overview

This project demonstrates how to:

  • Deploy a sample application to a Kubernetes cluster.
  • Expose the application using Kubernetes Services.
  • Scale the application using ReplicaSets.
  • Manage configurations using ConfigMaps and Secrets.
  • Clean up resources after deployment.
  • Implement GitOps practices using ArgoCD
  • Manage multiple environments (dev, staging, prod)
  • Automate deployments using Helm charts

The demo application is a simple web server that serves a static webpage or API endpoint.


Prerequisites

Before you begin, ensure you have the following installed:

  • Kubernetes Cluster: You can use a local cluster like Minikube, Kind, or a cloud-based cluster (e.g., GKE, EKS, AKS).
  • kubectl: The Kubernetes command-line tool. Installation guide.
  • Docker: To build and manage container images. Installation guide.

Getting Started

  1. Clone this repository:

    git clone https://github.com/JawherKl/k8s-demo.git
    cd k8s-demo
  2. Ensure your Kubernetes cluster is running:

    kubectl cluster-info
  3. Build the Docker image (if applicable):

    docker build -t your-username/k8s-demo-app:latest .
  4. Deploy the application to your cluster (see Deploying the Application).


Project Structure

k8s-demo/
├── manifests/               # Kubernetes YAML files
│   ├── deployment.yaml      # Deployment configuration
│   ├── service.yaml        # Service configuration
│   └── configmap.yaml      # ConfigMap for environment variables
├── helm/                   # Helm chart directory
│   └── webapp/            
│       ├── Chart.yaml      # Helm chart definition
│       ├── values.yaml     # Default values
│       ├── values-dev.yaml # Development values
│       └── templates/      # Helm templates
├── argocd/                 # ArgoCD configurations
│   └── projects/
│       └── webapp.yaml     # ArgoCD application definitions
├── src/                    # Application source code
├── Dockerfile              # Dockerfile for the application
└── README.md              # This file

Deploying the Application

  1. Apply the Kubernetes manifests:

    kubectl apply -f manifests/
  2. Verify the deployment:

    kubectl get pods
    kubectl get services
  3. Access the application:

    • If using a local cluster (e.g., Minikube), run:
      minikube service <service-name>
    • For cloud clusters, use the external IP or LoadBalancer endpoint provided by the service.

Scaling and Managing the Application

  • Scale the application:

    kubectl scale deployment <deployment-name> --replicas=3
  • Update the application:

    • Modify the deployment.yaml file or other manifests.
    • Reapply the changes:
      kubectl apply -f manifests/
  • View logs:

    kubectl logs <pod-name>

Cleaning Up

To delete the deployed resources:

kubectl delete -f manifests/

Helm Implementation

This project uses Helm for package management and deployment. The Helm chart structure is organized as follows:

Chart Structure

helm/webapp/
├── Chart.yaml          # Chart metadata
├── values.yaml         # Default values
├── values-dev.yaml     # Development values
├── values-staging.yaml # Staging values
├── values-prod.yaml    # Production values
└── templates/          # Helm templates
    ├── deployment.yaml
    ├── service.yaml
    ├── ingress.yaml
    ├── configmap.yaml
    ├── secret.yaml
    ├── hpa.yaml
    └── _helpers.tpl

Installation and Usage

  1. Install Helm (if not already installed):

    curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
  2. Add dependencies:

    helm repo add bitnami https://charts.bitnami.com/bitnami
    helm repo update
  3. Deploy to different environments:

    # Development
    helm install webapp-dev ./helm/webapp -f helm/webapp/values-dev.yaml -n development
    
    # Staging
    helm install webapp-staging ./helm/webapp -f helm/webapp/values-staging.yaml -n staging
    
    # Production
    helm install webapp-prod ./helm/webapp -f helm/webapp/values-prod.yaml -n production

Configuration Options

Key configurations available in values files:

webapp:
  replicaCount: 1
  image:
    repository: nanajanashia/k8s-demo-app
    tag: v1.0
    pullPolicy: IfNotPresent
  
  resources:
    requests:
      cpu: 250m
      memory: 256Mi
    limits:
      cpu: 500m
      memory: 512Mi

  service:
    type: NodePort
    port: 3000
    nodePort: 30100

mongodb:
  enabled: true
  auth:
    rootPassword: mongopassword
    username: mongouser
    password: mongopassword

Upgrading and Rolling Back

  • Upgrade a release:

    helm upgrade webapp-dev ./helm/webapp -f helm/webapp/values-dev.yaml -n development
  • Roll back to a previous release:

    # List release history
    helm history webapp-dev -n development
    
    # Roll back to a specific revision
    helm rollback webapp-dev 1 -n development

Helm Commands Reference

# Validate chart
helm lint ./helm/webapp

# See what will be installed
helm template webapp-dev ./helm/webapp -f values-dev.yaml

# List installed releases
helm list -n development

# Uninstall a release
helm uninstall webapp-dev -n development

GitOps Implementation

This project uses ArgoCD for GitOps-based deployments. The setup includes:

  1. Install ArgoCD:

    kubectl create namespace argocd
    kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
  2. Access ArgoCD UI:

    kubectl port-forward svc/argocd-server -n argocd 8080:443

    Get the initial admin password:

    kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
  3. Deploy Applications:

    kubectl apply -f argocd/projects/webapp.yaml

Environment Management

The project supports three environments:

  • Development: Automatic sync with pruning enabled
  • Staging: Automatic sync with pruning enabled
  • Production: Manual sync for safety

Each environment is configured in:

  • helm/webapp/values-{env}.yaml: Environment-specific configurations
  • argocd/projects/webapp.yaml: ArgoCD application definitions

GitOps Workflow

  1. Make changes to the Helm chart or values
  2. Commit and push to the repository
  3. ArgoCD automatically detects changes
  4. Changes are applied based on environment sync policies

Contributing

Contributions are welcome! If you'd like to improve this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature).
  3. Commit your changes (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature/your-feature).
  5. Open a Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

This repository contains a demonstration of deploying and managing applications using Kubernetes (k8s). It is designed to help users understand the basics of Kubernetes, including deployments, services, scaling, and other core concepts.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages