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:
-
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 -
Kubernetes Master and Node Simulation: For local Kubernetes cluster simulation,
Minikubeis 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 startThis will start a local Kubernetes cluster. You can interact with it using
kubectl, the Kubernetes command-line tool. -
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:ltsFor GitLab CI/CD, you'll need to configure
.gitlab-ci.ymlin your repository to define your CI/CD pipeline. -
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: 80Apply the deployment with
kubectl:kubectl apply -f deployment.yaml -
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 serviceto 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!