-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
154 lines (121 loc) · 5.89 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# =========== #
# Interface #
# =========== #
BLACK := $(shell tput -Txterm setab 0 && tput -Txterm setaf 7)
RED := $(shell tput -Txterm setab 1 && tput -Txterm setaf 0)
GREEN := $(shell tput -Txterm setab 2 && tput -Txterm setaf 0)
YELLOW := $(shell tput -Txterm setab 3 && tput -Txterm setaf 0)
LIGHTPURPLE := $(shell tput -Txterm setab 4 && tput -Txterm setaf 0)
PURPLE := $(shell tput -Txterm setab 5 && tput -Txterm setaf 7)
BLUE := $(shell tput -Txterm setab 4 && tput -Txterm setaf 0)
WHITE := $(shell tput -Txterm setab 7 && tput -Txterm setaf 0)
RESET := $(shell tput -Txterm sgr0)
BLUE_TEXT := $(shell tput -Txterm setaf 4)
RED_TEXT := $(shell tput -Txterm setaf 1)
YELLOW_TEXT := $(shell tput -Txterm setaf 3)
# ================== #
# Environment Vars #
# ================== #
.EXPORT_ALL_VARIABLES:
AKS_ENV_NAME=$(shell terraform output -json summary | jq -r .env)
AKS_ENV_HOSTNAME=$(shell terraform output -json summary | jq -r .hostname)
AKS_SUBSCRIPTION_ID=$(shell terraform output -json summary | jq -r .azure_subscription.id)
AKS_TENANT_ID=$(shell terraform output -json summary | jq -r .azure_subscription.tenant_id)
AKS_RG_NAME=$(shell terraform output -json summary | jq -r .resource_group.name)
AKS_CLUSTER_NAME=$(shell terraform output -json summary | jq -r .aks_cluster.name)
KUBELET_MI_CLIENT_ID=$(shell terraform output -json summary | jq -r .managed_identities.kubelet.client_id)
INGRESS_MI_CLIENT_ID=$(shell terraform output -json workloads | jq -r .ingress.managed_identity.client_id)
HELLO_WORLD_MI_CLIENT_ID=$(shell terraform output -json workloads | jq -r '.["hello-world"].managed_identity.client_id')
OIDC_ISSUER_URL=$(shell terraform output -json summary | jq -r .aks_cluster.oidc_issuer_url)
INGRESS_STATIC_IP_NAME=$(shell terraform output -json summary | jq -r .virtual_network.static_ingress_ip.name)
INGRESS_STATIC_IP_RG=$(shell terraform output -json summary | jq -r .virtual_network.resource_group)
CLUSTER_KV_NAME=$(shell terraform output -json summary | jq -r .key_vault.name)
KEY_VAULT_CSI_CHART_VERSION=1.5.4
INGRESS_CHART_VERSION=4.9.1 # older version works with Azure… 4.7 supposedly works, but need 4.8 for aks 1.28
INGRESS_NAMESPACE=ingress
# Key Vault Provider CSI Chart Versions
# https://github.com/Azure/secrets-store-csi-driver-provider-azure/tree/master/charts/csi-secrets-store-provider-azure
# Ingress Chart versions
# https://github.com/kubernetes/ingress-nginx?tab=readme-ov-file#supported-versions-table
# https://github.com/kubernetes/ingress-nginx/tags
# ========= #
# Scripts #
# ========= #
# Get AKS Credentials
kubecontext:
@echo "${PURPLE} Kubernetes ${RESET} Set Kubernetes context"
az aks get-credentials \
--resource-group ${AKS_RG_NAME} \
--name ${AKS_CLUSTER_NAME}
kubelogin convert-kubeconfig -l azurecli
kubectl get pods --all-namespaces
# All the commands
# ----------------
setup: create-namespaces install-azure-kv-csi install-ingress
uninstall: uninstall-ingress uninstall-azure-kv-csi delete-namespaces
# Namespaces
# ----------
create-namespaces:
@echo ""
@echo "${PURPLE} Namespaces ${RESET} ${YELLOW_TEXT}create${RESET}"
kubectl apply -f manifests/namespaces/
delete-namespaces:
@echo ""
@echo "${PURPLE} Namespaces ${RESET} ${RED_TEXT}delete${RESET}"
kubectl delete -f manifests/namespaces/
# CSI Driver
# ----------
install-azure-kv-csi:
@echo ""
@echo "${BLUE} Azure CSI ${RESET} ${YELLOW_TEXT}helm install${RESET}"
helm repo add csi-secrets-store-provider-azure https://azure.github.io/secrets-store-csi-driver-provider-azure/charts
helm repo update
helm upgrade azure-kv-csi csi-secrets-store-provider-azure/csi-secrets-store-provider-azure \
--set secrets-store-csi-driver.syncSecret.enabled=true \
--version $$KEY_VAULT_CSI_CHART_VERSION \
--namespace kube-system \
--install
uninstall-azure-kv-csi:
@echo ""
@echo "${BLUE} Azure CSI ${RESET} ${RED_TEXT}helm uninstall${RESET}"
helm uninstall azure-kv-csi --namespace kube-system
# Ingress Controller
# ------------------
install-ingress: sync-certs install-ingress-identity install-ingress-chart apply-hello
uninstall-ingress: remove-hello uninstall-ingress-chart uninstall-ingress-identity unsync-certs
sync-certs:
@cat ./manifests/ingress/secret-provider-classes.yaml | envsubst | kubectl apply -f -
unsync-certs:
@cat ./manifests/ingress/secret-provider-classes.yaml | envsubst | kubectl delete -f -
install-ingress-chart:
@echo ""
@echo "${PURPLE} Ingress ${RESET} ${YELLOW_TEXT}helm install${RESET}"
cat ./manifests/ingress/chart.values.yaml | envsubst | helm upgrade \
--install ingress-basic ingress-nginx \
--repo https://kubernetes.github.io/ingress-nginx \
--namespace $$INGRESS_NAMESPACE \
--version $$INGRESS_CHART_VERSION \
--timeout 2m30s \
-f -
sleep 60
uninstall-ingress-chart:
@echo ""
@echo "${PURPLE} Ingress ${RESET} ${RED_TEXT}helm uninstall${RESET}"
helm uninstall ingress-basic --namespace $$INGRESS_NAMESPACE
# Hello World
# -----------
apply-hello:
@echo ""
@echo "${PURPLE} Hello World ${RESET} ${YELLOW_TEXT}kubectl apply -f manifests/hello-world/…${RESET}"
@cat ./manifests/hello-world/service-account.yaml | envsubst | kubectl apply -f -
@cat ./manifests/hello-world/secret-provider-class.yaml | envsubst | kubectl apply -f -
@cat ./manifests/hello-world/deployment.yaml | envsubst | kubectl apply -f -
@cat ./manifests/hello-world/ingress.yaml | envsubst | kubectl apply -f -
@cat ./manifests/hello-world/service.yaml | envsubst | kubectl apply -f -
remove-hello:
@echo ""
@echo "${PURPLE} Hello World ${RESET} ${RED_TEXT}kubectl delete -f manifests/hello-world/…${RESET}"
@cat ./manifests/hello-world/secret-provider-class.yaml | envsubst | kubectl delete -f -
@cat ./manifests/hello-world/ingress.yaml | envsubst | kubectl delete -f -
@cat ./manifests/hello-world/service.yaml | envsubst | kubectl delete -f -
@cat ./manifests/hello-world/deployment.yaml | envsubst | kubectl delete -f -