Skip to content

Instantly share code, notes, and snippets.

@russomi
Last active April 16, 2021 20:58
Show Gist options
  • Save russomi/bd2ab688cf119b1d21465716c93d4221 to your computer and use it in GitHub Desktop.
Save russomi/bd2ab688cf119b1d21465716c93d4221 to your computer and use it in GitHub Desktop.
Links to GitOps resources
# Source: https://gist.github.com/ae00efa6892fcb0b295bbdba73bef3ad
# Minikube (minikube.sh): https://gist.github.com/2a6e5ad588509f43baa94cbdf40d0d16
# Install Argo CD CLI
brew install argocd
# Install kubectl - https://kubernetes.io/docs/tasks/tools/#kubectl
brew install kubectl
# Install Helm - https://helm.sh/docs/intro/install/
brew install helm
# Create Minikube cluster
export KUBECONFIG=$PWD/kubeconfig
minikube start --vm=true
minikube addons enable ingress
export INGRESS_HOST=$(minikube ip)
# Install Argo CD via Helm chart
kubectl create namespace argocd
# Add the Argo Chart Repo
helm repo add argo https://argoproj.github.io/argo-helm
# Install the chart
helm upgrade --install \
argocd argo/argo-cd \
--namespace argocd \
--version 3.0.0 \
--set server.ingress.hosts="{argocd.$INGRESS_HOST.xip.io}" \
--values argocd-values.yaml \
--wait
# Capture the default password
export PASS=$(kubectl \
--namespace argocd \
get secret argocd-initial-admin-secret \
--output jsonpath="{.data.password}" | base64 -d)
echo $PASS
# login via the cli
argocd login \
--insecure \
--username admin \
--password $PASS \
--grpc-web \
argocd.$INGRESS_HOST.xip.io
echo $PASS
argocd account update-password
open http://argocd.$INGRESS_HOST.xip.io
kubectl --namespace argocd get pods
# Deploying An Application With Argo CD
git clone \
https://github.com/vfarcic/devops-toolkit.git
cd devops-toolkit
ls -1 k8s
kubectl create namespace devops-toolkit
argocd app create devops-toolkit \
--repo https://github.com/vfarcic/devops-toolkit.git \
--path k8s \
--dest-server https://kubernetes.default.svc \
--dest-namespace devops-toolkit
open http://argocd.$INGRESS_HOST.xip.io
kubectl --namespace devops-toolkit \
get all
# Syncronize
kubectl --namespace devops-toolkit \
get all
argocd app delete devops-toolkit
open http://argocd.$INGRESS_HOST.xip.io
kubectl --namespace devops-toolkit \
get all
kubectl delete namespace devops-toolkit
ls -1 helm
cd ..
# Defining Whole Environments
# Replace `[...]` with the GitHub organization
export GH_ORG=gitops-labs
git clone \
https://github.com/$GH_ORG/argocd-production.git
cd argocd-production
cat project.yaml
kubectl apply \
--filename project.yaml
kubectl --namespace argocd \
get appprojects
open http://argocd.$INGRESS_HOST.xip.io/settings/projects
kubectl create namespace production
ls -1 helm
ls -1 helm/templates
cat helm/templates/devops-toolkit.yaml
cat helm/templates/devops-paradox.yaml
cat apps.yaml
cat apps.yaml \
| sed -e "s@vfarcic@$GH_ORG@g" \
| tee apps.yaml
git add .
git commit -m "Changed the org"
git push
kubectl --namespace argocd apply \
--filename apps.yaml
open http://argocd.$INGRESS_HOST.xip.io
kubectl --namespace production get all
kubectl --namespace production get ingresses
# Updating Applications Through GitOps Principles
cat helm/templates/devops-toolkit.yaml \
| sed -e "s@latest@2.9.17@g" \
| sed -e "s@devopstoolkitseries.com@devops-toolkit.$INGRESS_HOST.xip.io@g" \
| tee helm/templates/devops-toolkit.yaml
git add .
git commit -m "New release"
git push
kubectl --namespace production get \
deployment devops-toolkit-devops-toolkit \
--output jsonpath="{.spec.template.spec.containers[0].image}"
kubectl --namespace production get \
deployment devops-toolkit-devops-toolkit \
--output jsonpath="{.spec.template.spec.containers[0].image}"
kubectl --namespace production get ingresses
open http://devops-toolkit.$INGRESS_HOST.xip.io
rm helm/templates/devops-paradox.yaml
git add .
git commit -m "Removed DOP"
git push
open http://argocd.$INGRESS_HOST.xip.io
kubectl --namespace production get pods
############################
# Destroying The Resources #
############################
kubectl delete namespace argocd
kubectl delete namespace production
cd ..

Deploying Applications Using GitOps

GitOps - An operating model for building cloud native applications

Overview

  • GitOps is a way to do Kubernetes cluster management and application delivery.
  • Use of the Git version control system to track and approve changes to the infrastructure and runtime environment of applications.
  • The term "GitOps" was popularized in 2017 by Alexis Richardson of Weaveworks[1].
  • Developer-centric experience for managing applications and infrastructure.
  • Fully automated pipelines/workflows in Git are used for development and operations.

Principles

  1. The entire system is described declaratively
  2. The desired system state is versioned in Git
  3. Approved changes to the desired state are automatically applied to the system
  4. Software agents ensure correctness and alert on divergence

Benefits

  1. Increased Productivity - Mean Time to Deployment
  2. Enhanced Developer Experience - Push code and not containers
  3. Improved Compliance and Stability - Git provides an audit log for changes
  4. Higher Reliability - Git capability to revert/rollback, Mean-Time-To-Recovery (MTTR)
  5. Increased Consistency and Standardization - infrastructure, apps, and Kubernetes driven by consistent workflow - Pull Requests
  6. Stronger Security Guarantees - Git strong correctness and security guarantees, ability to sign changes to prove authorship and origin

Declarative vs. Imperative Model

  • Declarative models describe the desired state
  • Imperative models describe a sequence of instructions to achieve the desired state
  • Declarative systems are idempotent; imperative systems are not
  • Kubernetes is a declarative system that regularly reconciles desired state with the running state

Deployments and Environments

  • Application deployments are defined using declarative format
  • Applications are deployed to environments
  • An environment is a collection of applications and associated resources
  • An environment could be a Kubernetes namespace, the whole cluster, or multiple federated clusters
  • Production, Staging, and Preview are examples of environments
  • Environments define the desired state of a collection of applications and resources
  • We need to be able to update the state of the environment to reflect the desire to have a new version of the application deployed
  • Environment repositories contain references to all the manifests of individual applications and environment specific parameters
  • We have individual applications and environments

Deploying Applications Using GitOps Principles

  • ArgoCD
  • Flux

Creating Kubernetes with Terraform

Prerequisites

Configure Credentials

aws configure sso
asp pegasus-alz-dev15-AdministratorAccess
export-aws-credentials

Create Remote Backend

# generate a unique bucket name
export TF_VAR_state_bucket=gitops-labs-$(date +%Y%m%d%H%M%S)
echo $TF_VAR_state_bucket

# create the remote backend bucket
aws s3 mb s3://$TF_VAR_state_bucket

Create the EKS Cluster

terraform apply

export KUBECONFIG=$PWD/kubeconfig

aws eks update-kubeconfig \
    --name \
    $(terraform output -raw cluster_name) \
    --region \
    $(terraform output -raw region)

kubectl get nodes

# Note: This does not work on a brand new account due to a missing service linked role.
# https://github.com/terraform-aws-modules/terraform-aws-eks/issues/183#issuecomment-435315065
# Create Ingress Controller
kubectl apply \
    --filename https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.45.0/deploy/static/provider/aws/deploy.yaml

export INGRESS_HOST=$(kubectl \
    --namespace ingress-nginx \
    get svc ingress-nginx-controller \
    --output jsonpath="{.status.loadBalancer.ingress[0].hostname}")

echo $INGRESS_HOST

# Destroy the resources

kubectl apply \
    --filename https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.45.0/deploy/static/provider/aws/deploy.yaml

terraform destroy

Links


Packaging, Deploying, And Managing Applications

Step 1

Step 2

Step 3

Resources


Deploying Applications Using GitOps Principles with ArgoCD

Prerequisties

  • Create a cluster with ingress
minikube start --vm=true
minikube addons enable ingress
export INGRESS_HOST=$(minikube ip)
  • Install ArgoCD CLI
# Only if macOS
brew tap argoproj/tap
# Only if macOS
brew install argoproj/tap/argocd
  • Install Helm CLI

Step 1 - Install ArgoCD with Helm

Step 2

Step 3

Resources


Resources

Links to GitOps resources

Weaveworks

The DevOps Toolkit Series

Helm

Blogs

https://go.weave.works/rs/249-YDT-025/images/eBook_ThePracticalGuideToGitOps.pdf?mkt_tok=MjQ5LVlEVC0wMjUAAAF8PbmvM8exI1MmzReJiOnHki3ekEar4Wdyw73k3rlS2v5h2CjHwFDC0Fom3T2F9vcMaSuCH6kD-0BHpzDFws9ZHFa5h-6uyaty5fI9laenUg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment