This project automates the setup of a local Kubernetes (K3s) environment with Minikube and ArgoCD, allowing easy management of clusters and resources.
Before running the script, ensure you have the following installed:
- Docker
- Minikube
- kubectl
- ArgoCD CLI
- Python 3.x with pip
pip install pyyamlargocd-environment/
├── argocd-ingress.yaml
├── projects/ # Project definitions for ArgoCD
├── repos/ # Repository definitions for ArgoCD
├── cluster.json # JSON file with K3s cluster definitions
├── main.py # Main script to set up the environment
└── k3s-clusters.yml # Generated YAML file for K3s clusters
{
"dev": 6444,
"stage": 6445,
"prod": 6446
}projects/
└── devopsproject.yaml
repos/
└── private-repo-using-token.yaml
git clone https://github.com/ITBeyder/argocd-environment.git
cd argocd-environmentDefine the K3s clusters and their ports:
{
"dev": 6444,
"stage": 6445,
"prod": 6446
}python main.pyFind the ArgoCD admin password in argocd_admin_password.txt.
sudo vi /etc/hosts
127.0.0.1 argocd.minikube.localOpen your browser at: http://argocd.minikube.local
Default login is admin and the password from argocd_admin_password.txt.
apiVersion: v1
kind: Secret
metadata:
name: token-private-repo
namespace: argocd
labels:
argocd.argoproj.io/secret-type: repository
stringData:
type: git
url: https://github.com/<USERNAME>/<REPO>.git
username: <REPO>
password: <TOKEN>apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: <Project_Name>
namespace: argocd
spec:
clusterResourceWhitelist:
- group: '*'
kind: '*'
description: "This is the devops project"
destinations:
- namespace: '*'
server: '*'
sourceRepos:
- '*'
roles:
- name: read-only-user
description: "this role can be used for reading and sync applications"
policies:
- p, proj:project-role:read-only, applications, get, project-role/*, allow
- name: admin
description: "this role can be used for admin operations"
policies:
- p, proj:project-role:admin, applications, *, project-role/*, allow
- name: sync-user
description: "this role can be used for sync applications"
policies:
- p, proj:project-role:sync-user, applications, sync, project-role/*, allow
# Example commands to generate and use tokens:
# argocd proj role create-token project-role read-sync-user
# argocd app list --auth-token xxxxxTo stop and remove all K3s clusters:
docker rm -f $(docker ps -a -q --filter "name=k3s-")
docker volume rm $(docker volume ls -q --filter "name=k3s-")