Skip to content

hckops/kube-template

Repository files navigation

kube-template

kube-do helm-dependencies

Spin-up a platform with a git push!

Setup

  1. Create a new repository from this template
    • it works both with Public and Private repositories
    • naming convention: kube-<CLUSTER_NAME> or <CLUSTER_NAME>-k8s
  2. Replace repository URL
    OLD_REPOSITORY=git@github.com:hckops/kube-template.git
    NEW_REPOSITORY=<HTTPS_OR_SSH_GIT_URL>
    
    grep -Rl --exclude=*.md --exclude-dir=.git ${OLD_REPOSITORY} . | xargs \
      sed -i "s|${OLD_REPOSITORY}|${NEW_REPOSITORY}|g"
  3. Rename cluster name and definition clusters/kube-<CLUSTER_NAME>.yaml
    grep -Rl --exclude-dir=.git "do-template" . | xargs \
      sed -i "s|do-template|<CLUSTER_NAME>|g"
  4. Override the credential template with the right owner
    # argocd-config/values-bootstrap.yaml
    + argocd.configs.credentialTemplates.ssh-creds.url: git@github.com:<OWNER_OR_REPOSITORY>
    - argocd.configs.credentialTemplates.ssh-creds.url: git@github.com:hckops
  5. Add the following action secrets
    • DIGITALOCEAN_ACCESS_TOKEN required to privision a cluster with DigitalOcean
    • ARGOCD_ADMIN_PASSWORD and ARGOCD_GIT_SSH_KEY required to bootstrap this platform with ArgoCD
    • DISCORD_WEBHOOK_URL optional, to notify the status in a Discord channel
    • for more info see workflow and hckops/actions
  6. Update the cluster definition and push all the changes
    # clusters/kube-<CLUSTER_NAME>.yaml
    + status: UP
    - status: DOWN
    or simply create the cluster by running
    make cluster-up
  7. Wait... 🚀

discord-message

  1. Connect to ArgoCD
    # download kubeconfig
    make kube-config
    
    # https://localhost:8080
    # [admin|<ARGOCD_ADMIN_PASSWORD>]
    make forward-argocd

argocd-ui

  1. Sample apps
    # http://localhost:8090
    kubectl --kubeconfig clusters/do-template-kubeconfig.yaml -n examples \
      port-forward svc/guestbook-ui 8090:80
    
    # http://localhost:8091
    kubectl --kubeconfig clusters/do-template-kubeconfig.yaml -n examples \
      port-forward svc/hello-kubernetes-gitops 8091:80
  2. Alternatively, access the cluster from a container
    # use "--network host" to solve dns issues locally or edit "/etc/docker/daemon.json"
    docker run --rm --name hck-tmp -it \
      -e KUBECONFIG=/root/.kube/config \
      -v ${PWD}/clusters/do-template-kubeconfig.yaml:/root/.kube/config \
      hckops/kube-argo
    
    # with docker-compose
    docker-compose up -d
    docker exec -it local-hck-template bash
    docker-compose down -v
    
    # login with kubeconfig
    argocd login --core
    
    # list apps
    kubens argocd
    kubectl get applications
    argocd app list
    
    # watch resources
    kubectl klock -n examples pods
  3. Destroy the cluster
    make cluster-down