Mega_Aleksandar's avatar

Local simulation of production environments

Hello everyone,

In this question or thread, I would like to get some help or any pointers regarding the following idea: Simulation of a production environment localy using Docker containers

  • One container to act as GitHub (or even utilize the GitHub CI/CD)
  • One container to act as the Kubernetes master
  • One to act as a Kubernetes node with pod(s) with the application

The point is, as curious as I am, it would be really nice to see the internal workings of that setup and have complete control (aka. want to break it, fix it etc.).

Currently I have grasped the concepts of Docker (and its yaml files), but I am lacking the Kubernetes cluster part and would love to be able to have the complete Developer->CI/CD->Container->Kubernetes cycle under control.

Did my research, found about the Minikube and kind, but I am still lacking the confidence to test them out until I get some input from someone with more experience.

Thank you for your time. Mega_Aleksandar

0 likes
3 replies
LaryAI's avatar
Level 58

Hello Mega_Aleksandar,

Simulating a production environment locally is a great way to understand the deployment process and the interactions between different components. Here's a step-by-step guide to setting up a local simulation of a production environment using Docker and Kubernetes:

  1. GitHub Simulation: You can use a Docker container to simulate a GitHub environment. However, for local development, you might not need a full-fledged GitHub container. Instead, you can use Git within your local environment or a lightweight Git server like Gitea or GitLab running in a container.

    If you want to proceed with a containerized Git server, you can use the official GitLab Docker image:

    docker run --detach \
      --hostname gitlab.example.com \
      --publish 443:443 --publish 80:80 --publish 22:22 \
      --name gitlab \
      --restart always \
      --volume /srv/gitlab/config:/etc/gitlab \
      --volume /srv/gitlab/logs:/var/log/gitlab \
      --volume /srv/gitlab/data:/var/opt/gitlab \
      gitlab/gitlab-ce:latest
    
  2. Kubernetes Master and Node Simulation: For local Kubernetes cluster simulation, Minikube is a great tool to start with. It runs a single-node Kubernetes cluster inside a VM on your laptop for users looking to try out Kubernetes or develop with it day-to-day.

    Install Minikube following the instructions on the official Minikube GitHub page.

    Once installed, start Minikube with:

    minikube start
    

    This will start a local Kubernetes cluster. You can interact with it using kubectl, the Kubernetes command-line tool.

  3. CI/CD Simulation: For CI/CD, you can use Jenkins or GitLab CI/CD. Jenkins can be run in a Docker container, and GitLab CI/CD can be integrated with the GitLab container mentioned earlier.

    To run Jenkins in a Docker container, use the following command:

    docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
    

    For GitLab CI/CD, you'll need to configure .gitlab-ci.yml in your repository to define your CI/CD pipeline.

  4. Application Deployment: With your Kubernetes cluster running via Minikube, you can now deploy your application using kubectl. First, you'll need to create a Docker image for your application and make it available to Minikube.

    Build your Docker image:

    eval $(minikube docker-env)
    docker build -t my-application:v1 .
    

    Then, create a Kubernetes deployment:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: my-application
    spec:
      selector:
        matchLabels:
          app: my-application
      replicas: 2
      template:
        metadata:
          labels:
            app: my-application
        spec:
          containers:
          - name: my-application
            image: my-application:v1
            ports:
            - containerPort: 80
    

    Apply the deployment with kubectl:

    kubectl apply -f deployment.yaml
    
  5. Testing and Experimentation: Now that you have your local environment set up, you can test the CI/CD pipeline by making changes to your application, committing them to your Git server, and observing the build and deployment process.

    To access your application, you can use minikube service to expose it:

    kubectl expose deployment my-application --type=NodePort
    minikube service my-application
    

Remember, this setup is for learning and experimentation purposes and may differ from a production setup, especially in terms of security and scalability. However, it's a great way to get hands-on experience with the full development to deployment cycle. Enjoy your learning journey!

1 like
Mega_Aleksandar's avatar

Thank you Lary.

On another note, I want to double check my concepts about Kubernetes.

It is basically, one Master machine (like a VPS), and then at least one Node machine (another VPS). Connect them in a VPN and then, if I need to scale, I can just add more VPS as Nodes and connect them to the same VPN. The Master needs to be a bit more powerfull than the Nodes, to handle the load balancing and those things.

Ofcourse, adding new VPS vs upgrading the same one with more power is a thing to consider cost wise, but that is another topic.

Thank you for reading.

Best regards,

Mega_Aleksandar

Mega_Aleksandar's avatar

Hello,

For anyone ending up here, make sure that, when you run minikube start you use the docker driver, not the default hyperv driver.

Will continue to update as I come about more stuff here. For now everything is working, except the gitlab part, but I did not have time to tinker with that, yet.

1 like

Please or to participate in this conversation.