GitOps Principles
What is GitOps?
GitOps is an operational framework that applies DevOps best practices used for application development (version control, collaboration, CI/CD) to infrastructure automation.
Declarative
Infrastructure is described declaratively in Git
Versioned
All changes are tracked with full audit history
Automated
Changes are automatically applied to infrastructure
Auditable
Complete history of who changed what and when
Core Principles
1. Declarative Configuration
Infrastructure is defined in a declarative way, describing the desired state rather than imperative steps.
apiVersion: v1kind: Clustermetadata: name: production region: PHX1spec: provider: civo nodes: - g4s.kube.large - g4s.kube.large - g4s.kube.large2. Version Controlled
All infrastructure definitions are stored in Git repositories, providing:
Change History
Every change is tracked with commit messages:
git log clusters/production.yamlSee who made changes, when, and why.
Rollback Capability
Easily revert to previous states:
git revert HEADhyve reconcileThe infrastructure returns to the previous configuration.
Collaboration
Multiple team members can propose changes:
# Create feature branchgit checkout -b add-monitoring-cluster
# Add cluster definitionhyve cluster add monitoring --provider civo --region NYC1
# Create pull request for reviewgit push origin add-monitoring-clusterAudit Trail
Complete history of infrastructure changes:
git log --oneline clusters/# 387184b Add monitoring cluster# 40e1298 Scale production to 3 nodes# 0f395fc Update development region3. Automated Synchronization
Changes in Git automatically reconcile to the infrastructure:
# Make change in Githyve cluster add new-cluster --provider civo --region PHX1
# Commit the changegit add clusters/new-cluster.yamlgit commit -m "Add new cluster"
# Reconcile applies the changehyve reconcile4. Single Source of Truth
Git repositories are the single source of truth for infrastructure state:
Define in Git
All cluster definitions exist in Git repositories
~/.hyve/repositories/production/clusters/├── production.yaml├── staging.yaml└── development.yamlCommit Changes
Changes are committed to version control
git add clusters/production.yamlgit commit -m "Scale production cluster"Reconcile State
Hyve ensures cloud matches Git
hyve reconcile# Creates, updates, or deletes resources to match GitGitOps Workflow with Hyve
Traditional Approach (Imperative)
# Manual commands without version controlcivo kubernetes create production --nodes 3 --size g4s.kube.largecivo kubernetes scale production --nodes 5civo kubernetes delete staging
# No history, no audit trail, no collaborationGitOps Approach (Declarative)
# 1. Define desired state in Githyve cluster add production --provider civo --region PHX1 --nodes g4s.kube.large,g4s.kube.large,g4s.kube.large
# 2. Review the generated YAMLcat ~/.hyve/repositories/production/clusters/production.yaml
# 3. Commit to Gitgit add clusters/production.yamlgit commit -m "Add production cluster with 3 nodes"
# 4. Reconcile applies changeshyve reconcile
# 5. Make changes by editing YAML# Edit clusters/production.yaml to add more nodes
# 6. Commit and reconcilegit commit -am "Scale production to 5 nodes"hyve reconcileBenefits of GitOps
Increased Velocity
Faster deployments with automation and standardization
Enhanced Stability
Reduced errors through declarative configurations and automated validation
Better Collaboration
Team members review changes via pull requests before deployment
Improved Security
All changes tracked with audit trails and approval workflows
Easy Rollbacks
Instant rollback to any previous state using Git history
Disaster Recovery
Entire infrastructure can be recreated from Git repository
Hyve’s GitOps Implementation
Multi-Repository Support
Separate repositories for different environments:
# Production repositoryhyve git add production --repo-url https://github.com/company/hyve-prod.git
# Staging repositoryhyve git add staging --repo-url https://github.com/company/hyve-staging.git
# Development repositoryhyve git add development --repo-url https://github.com/company/hyve-dev.gitEach repository maintains:
- Cluster definitions (
clusters/) - Workflow definitions (
workflows/) - Template definitions (
templates/)
Reconciliation
Hyve continuously ensures cloud infrastructure matches Git:
# Manual reconciliationhyve reconcile
# Reconcile specific clusterhyve reconcile --cluster production
# Dry run (preview changes)hyve reconcile --dry-runWorkflow Automation
Automated deployment pipelines defined in Git:
apiVersion: v1kind: Workflowmetadata: name: deploy-appspec: requirements: tools: - name: kubectl version: "1.28" jobs: - name: deploy steps: - name: apply-manifests command: kubectl apply -f manifests/GitOps Best Practices
1. Use Descriptive Commit Messages
Write clear commit messages explaining why changes were made:
# Goodgit commit -m "Scale production cluster for increased load during holiday season"
# Badgit commit -m "Update cluster"2. Review Changes via Pull Requests
Always use pull requests for production changes:
# Create feature branchgit checkout -b scale-production
# Make changeshyve cluster add production --provider civo --region NYC1 --nodes g4s.kube.large,g4s.kube.large,g4s.kube.large
# Commit and pushgit commit -am "Scale production cluster to 3 nodes"git push origin scale-production
# Create PR for team review3. Separate Environments
Use different repositories for different environments:
# Productionhyve git add production --repo-url https://github.com/company/hyve-prod.git
# Staginghyve git add staging --repo-url https://github.com/company/hyve-staging.git4. Automate Reconciliation
Set up automated reconciliation in CI/CD:
# In CI/CD pipelinehyve reconcile --cluster production5. Test Changes in Development First
Always test changes in development before production:
# Switch to developmenthyve git use development
# Test changeshyve cluster add test-cluster --provider civo --region PHX1hyve reconcile
# Verify it works, then apply to productionhyve git use productionhyve cluster add production-cluster --provider civo --region NYC1GitOps vs Traditional
| Aspect | Traditional | GitOps |
|---|---|---|
| State Storage | Cloud console / CLI | Git repository |
| Change Method | Manual commands | Git commits |
| Audit Trail | Limited / None | Complete Git history |
| Rollback | Manual / Difficult | git revert |
| Collaboration | Shared credentials | Pull requests |
| Automation | Custom scripts | Declarative workflows |
| Security | Risky | Audited & reviewed |
Real-World Example
Scenario: Scale Production Cluster
# Developer runs command manuallycivo kubernetes scale production --nodes 5
# Problems:# - No record of who made the change# - No explanation of why# - No review process# - Hard to rollback# - Team members unaware# 1. Developer creates branchgit checkout -b scale-production
# 2. Updates cluster definition# Edit clusters/production.yaml to add nodes
# 3. Commits with explanationgit commit -am "Scale production to 5 nodes for holiday traffic spike"
# 4. Creates pull requestgit push origin scale-production
# 5. Team reviews and approves# PR shows exact changes, team discusses
# 6. Merge triggers reconciliationgit checkout maingit merge scale-productionhyve reconcile
# Benefits:# ✅ Full audit trail# ✅ Team awareness# ✅ Review process# ✅ Easy rollback (git revert)# ✅ Documented reasoningDisaster Recovery
With GitOps, recovering from disasters is straightforward:
Clone Repository
git clone https://github.com/company/hyve-prod.gitcd hyve-prodConfigure Hyve
hyve git add production --repo-url https://github.com/company/hyve-prod.git# Authenticate with the Civo CLI (writes ~/.civo.json)civo apikey save my-token YOUR_CIVO_TOKEN && civo apikey use my-tokenReconcile Infrastructure
hyve reconcile# Recreates all clusters from Git definitions