Files
dc-kc/Makefile
2023-09-20 21:31:42 +01:00

94 lines
4.5 KiB
Makefile

CHART_DIR_PATH_ARGO="charts/init"
ARGO_NAMESPACE="argocd"
ACD=argo-cd
ACD_VERSION=5.46.6
REGISTRY="registry.gitlab.com"
FORWARD_PORT="8021"
MINIKUBE_KUBE_VERSION=1.27.4
REGCRED_NAME="regcred"
DEEPCYOHER_NAMESPACE=deepcypher
# additional args for setting podman auth.json config
# https://docs.podman.io/en/latest/markdown/podman-login.1.html
DOCKER_AUTH_FILE="${HOME}/.docker/config.json"
REGISTRY_AUTH_FILE="${HOME}/.podman/auth.json"
# this will override the charts values.yaml to let the chart know it should either run in "cloud" or "metal" mode.
# The only difference should be storage and loadbalancing since on bare-metal we have to do it ourselves.
KUBE_TYPE=metal
# Cloudflared settings
CLUSTER_NAME=arbiter
CLOUDFLARED_TUNNEL_CRED_FILE="${HOME}/.cloudflared/${CLUSTER_NAME}.yaml"
.PHONY: help
help: ## display this auto generated help message
@echo "Please provide a make target:"
@grep -F -h "##" $(MAKEFILE_LIST) | grep -F -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
.PHONY: all
all: minikube install forward ## create a basic minikube cluster to launch the stack onto
.PHONY: install
install: #login.lock ## bootstrap cluster into default kubeconfig location
helm repo add argocd https://argoproj.github.io/argo-helm/
helm dependency update ${CHART_DIR_PATH_ARGO}
#kubectl create namespace ${DEEPCYOHER_NAMESPACE} && kubectl apply -f login.creds
helm upgrade --install --create-namespace --namespace ${ARGO_NAMESPACE} -f argocd-values.yaml ${ACD} argocd/argo-cd --version ${ACD_VERSION}
helm upgrade --install --create-namespace --namespace ${ARGO_NAMESPACE} --set="type=${KUBE_TYPE}" init ${CHART_DIR_PATH_ARGO}
.PHONY: forward
forward: ## forward local port to argocd server deployment for secure preview
kubectl wait --timeout=600s --for=condition=Available=True -n ${ARGO_NAMESPACE} deployment ${ACD}-argocd-server
kubectl -n ${ARGO_NAMESPACE} get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d && echo
xdg-open "https://localhost:${FORWARD_PORT}?username=admin?password=" &
kubectl port-forward svc/${ACD}-argocd-server -n ${ARGO_NAMESPACE} ${FORWARD_PORT}:443
.PHONY: proxy
proxy: ## creare some minikube proxy and a socat forward to proxy traffic over 443
minikube -n ingress service ingress-ingress-nginx-controller --url
# please set auth.deepcypher.me, deepcypher.me, docs.deepcypher.me api.deepcypher.me to the TCP ip redirected after this message
sudo socat TCP-LISTEN:443,fork TCP:192.168.49.2:30443
.PHONY: uninstall
uninstall: ## uninstall this bootstrap but this will not remove argocd as it needs to reconcile
helm uninstall --namespace ${ARGO_NAMESPACE} init
.PHONY: upgrade
upgrade: ## upgrade both argocd and the bootstrap
helm upgrade --namespace ${ARGO_NAMESPACE} -f argocd-values.yaml ${ACD} argocd/argo-cd --version ${ACD_VERSION}
helm upgrade --namespace ${ARGO_NAMESPACE} --set="type=${KUBE_TYPE}" init ${CHART_DIR_PATH_ARGO}
.PHONY: login
login: login.lock
login.lock:
podman login ${REGISTRY}
kubectl create -n ${DEEPCYOHER_NAMESPACE} secret generic ${REGCRED_NAME} --from-file=.dockerconfigjson=${REGISTRY_AUTH_FILE} --type=kubernetes.io/dockerconfigjson --dry-run=client -o yaml > login.creds
touch login.lock
.PHONY: patch-regcred
patch-regcred: login.lock
kubectl apply -f login.creds
.PHONY: minikube
minikube: ## create a minikube cluster by first deleting minikube then creating a new one with calico etc
minikube delete
minikube start --cni calico --driver=podman --kubernetes-version=${MINIKUBE_KUBE_VERSION}
# minikube addons enable ingress
# OR forward URL and edit /etc/hosts to point to 127.0.0.1
# minikube -n ingress service ingress-ingress-nginx-controller --url
# sudo socat TCP-LISTEN:443,fork TCP:<URL>:30443
# THIS IS VERY IMPORTANT PLEASE FOR THE LOVE OF GOD BACK THIS UP
# You need this master key to be able to decrypt your secrets in the cluster in future
master.key:
kubectl -n sealed-secrets get secret -l sealedsecrets.bitnami.com/sealed-secrets-key -o yaml > master.key
.PHONY: stuck
stuck: ## find stuck resources in argocd namespace
kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -n ${ARGO_NAMESPACE}
.PHONY: argotunnel
argotunnel: master.key ## Generate encrypted cloudflared argo tunnel for this cluster
cloudflared tunnel create metal --output yaml --credentials-file ${CLOUDFLARED_TUNNEL_CRED_FILE}
kubectl create secret generic tunnel-credentials --from-file=credentials.json=${CLOUDFLARED_TUNNEL_CRED_FILE} --dry-run=client -o yaml > ${CLUSTER_NAME}.cloudflared.yaml