Deploy Your First Application
Learn how to deploy applications using KubeZero's GitOps approach with ArgoCD.
Understanding GitOps in KubeZero
KubeZero follows GitOps principles where:
- Git is the single source of truth
- All changes are made through Git commits
- ArgoCD automatically syncs changes to the cluster
- Everything is declarative and version-controlled
Method 1: Using ArgoCD Applications
Step 1: Create Application Manifests
Create a simple nginx application:
mkdir -p apps/nginx
Create apps/nginx/deployment.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.21
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx
namespace: default
spec:
selector:
app: nginx
ports:
- port: 80
targetPort: 80
type: ClusterIP
Step 2: Create ArgoCD Application
Create apps/nginx/application.yaml
:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: nginx-app
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/your-username/your-repo
targetRevision: HEAD
path: apps/nginx
destination:
server: https://kubernetes.default.svc
namespace: default
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
Step 3: Apply and Sync
# Apply the ArgoCD application
kubectl apply -f apps/nginx/application.yaml
# Check the application status
kubectl get applications -n argocd
# View in ArgoCD UI
open http://gitops.local.kubezero.io
Method 2: Using KubeZero Modules
KubeZero provides reusable modules for common applications. Let's deploy using the module pattern:
Step 1: Create a Custom Stack
mkdir -p stacks/my-app/manifests
Create stacks/my-app/manifests/kustomization.yaml
:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- service.yaml
commonLabels:
app.kubernetes.io/name: my-app
app.kubernetes.io/managed-by: kubezero
namespace: my-app
Step 2: Add Application Resources
Create your application manifests in the manifests/
directory:
stacks/my-app/manifests/deployment.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: app
image: nginx:alpine
ports:
- containerPort: 80
Step 3: Register with ArgoCD
Create registry/my-app/_gitops.yaml
:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my-app
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/your-username/kubezero
targetRevision: HEAD
path: stacks/my-app/manifests
destination:
server: https://kubernetes.default.svc
namespace: my-app
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
Method 3: Using Virtual Clusters
For isolated environments, deploy to a virtual cluster:
Step 1: Create vCluster
# Apply vCluster configuration
kubectl apply -f - <<EOF
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: dev-vcluster
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/kubezero/kubezero
targetRevision: HEAD
path: modules/vcluster
destination:
server: https://kubernetes.default.svc
namespace: vcluster-dev
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- CreateNamespace=true
EOF
Step 2: Connect to vCluster
# Install vCluster CLI
curl -L -o vcluster "https://github.com/loft-sh/vcluster/releases/latest/download/vcluster-linux-amd64" && sudo install -c -m 0755 vcluster /usr/local/bin
# Connect to the virtual cluster
vcluster connect dev-vcluster -n vcluster-dev
Step 3: Deploy to vCluster
# Deploy your application to the virtual cluster
kubectl apply -f apps/nginx/deployment.yaml
Monitoring Your Deployment
Check Application Status
# List all ArgoCD applications
kubectl get applications -n argocd
# Get detailed status
kubectl describe application nginx-app -n argocd
# Check pods
kubectl get pods -n default
ArgoCD Dashboard
Access the ArgoCD dashboard to visually monitor your applications:
- Visit
http://gitops.local.kubezero.io
- Login with admin credentials
- View your applications and their sync status
- Monitor deployment health and history
Logs and Debugging
# View application logs
kubectl logs -l app=nginx -n default
# Check ArgoCD application controller logs
kubectl logs -n argocd -l app.kubernetes.io/name=argocd-application-controller
# Describe resources for troubleshooting
kubectl describe deployment nginx -n default
Best Practices
1. Use Proper Labeling
Always include consistent labels:
metadata:
labels:
app.kubernetes.io/name: my-app
app.kubernetes.io/version: "1.0.0"
app.kubernetes.io/component: web
app.kubernetes.io/managed-by: kubezero
2. Environment-Specific Configuration
Use Kustomize overlays for different environments:
stacks/my-app/
├── base/
│ ├── kustomization.yaml
│ └── deployment.yaml
└── overlays/
├── dev/
│ └── kustomization.yaml
└── prod/
└── kustomization.yaml
3. Health Checks
Include readiness and liveness probes:
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
Next Steps
- Working with Modules - Learn to create reusable components
- Managing Environments - Set up dev/staging/prod environments
- Security Best Practices - Secure your applications and platform
Congratulations! You've successfully deployed your first application with KubeZero. 🎉