This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
local-install.sh
executable file
·245 lines (220 loc) · 7.53 KB
/
local-install.sh
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/bin/bash
# import helpers
. scripts/common.sh
# Check for required tools
for tool in "helm" "kind" "kubectl"
do
if ! command_exists "$tool"; then
echo "This script relies on $tool. Install with 'brew install $tool' (assuming you're on Mac)";
exit 1;
fi
done
# Version check for `helm`
HELM_VERSION=$(helm version --template='{{.Version}}')
HELM_MAJOR_VERSION=$(echo ${HELM_VERSION:1} | cut -d'.' -f1)
HELM_MINOR_VERSION=$(echo $HELM_VERSION | cut -d'.' -f2)
if ! ( [[ "$HELM_MAJOR_VERSION" -gt 3 ]] || ( [[ "$HELM_MAJOR_VERSION" -eq 3 ]] && [[ "$HELM_MINOR_VERSION" -gt 9 ]] ) ); then
echo "Unsupported version of helm - update to at least 3.10.0 for support for '--set-json'"
exit 1
fi
# set up kind cluster
kind create cluster --name backstack --wait 5m --config=- <<- EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
EOF
# configure ingress
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.1/deploy/static/provider/kind/deploy.yaml
kubectl wait --namespace ingress-nginx --for=condition=ready pod --selector=app.kubernetes.io/component=controller --timeout=90s
# install crossplane
helm upgrade --install crossplane --namespace crossplane-system --create-namespace crossplane-stable/crossplane --set args='{--enable-external-secret-stores}' --wait
# install vault ess plugin
helm upgrade --install ess-plugin-vault oci://xpkg.upbound.io/crossplane-contrib/ess-plugin-vault --namespace crossplane-system --set-json podAnnotations='{"vault.hashicorp.com/agent-inject": "true", "vault.hashicorp.com/agent-inject-token": "true", "vault.hashicorp.com/role": "crossplane", "vault.hashicorp.com/agent-run-as-user": "65532"}'
waitfor default crd configurations.pkg.crossplane.io
# install back stack
kubectl apply -f - <<-EOF
apiVersion: pkg.crossplane.io/v1
kind: Configuration
metadata:
name: back-stack
spec:
package: ghcr.io/opendev-ie/back-stack-configuration:v1.0.3
EOF
# configure provider-helm for crossplane
waitfor default crd providerconfigs.helm.crossplane.io
kubectl wait crd/providerconfigs.helm.crossplane.io --for=condition=Established --timeout=1m
SA=$(kubectl -n crossplane-system get sa -o name | grep provider-helm | sed -e 's|serviceaccount\/|crossplane-system:|g')
kubectl create clusterrolebinding provider-helm-admin-binding --clusterrole cluster-admin --serviceaccount="${SA}"
kubectl create -f - <<- EOF
apiVersion: helm.crossplane.io/v1beta1
kind: ProviderConfig
metadata:
name: local
spec:
credentials:
source: InjectedIdentity
EOF
# configure provider-kubernetes for crossplane
waitfor default crd providerconfigs.kubernetes.crossplane.io
kubectl wait crd/providerconfigs.kubernetes.crossplane.io --for=condition=Established --timeout=1m
SA=$(kubectl -n crossplane-system get sa -o name | grep provider-kubernetes | sed -e 's|serviceaccount\/|crossplane-system:|g')
kubectl create clusterrolebinding provider-kubernetes-admin-binding --clusterrole cluster-admin --serviceaccount="${SA}"
kubectl create -f - <<- EOF
apiVersion: kubernetes.crossplane.io/v1alpha1
kind: ProviderConfig
metadata:
name: local
spec:
credentials:
source: InjectedIdentity
EOF
# configure provider-azure for crossplane
waitfor default crd providerconfigs.azure.upbound.io
kubectl wait crd/providerconfigs.azure.upbound.io --for=condition=Established --timeout=1m
kubectl create -f - <<- EOF
apiVersion: azure.upbound.io/v1beta1
kind: ProviderConfig
metadata:
name: default
spec:
credentials:
source: Secret
secretRef:
namespace: crossplane-system
name: azure-secret
key: credentials
EOF
# configure provider-aws for crossplane
waitfor default crd providerconfigs.aws.upbound.io
kubectl wait crd/providerconfigs.aws.upbound.io --for=condition=Established --timeout=1m
kubectl create -f - <<- EOF
apiVersion: aws.upbound.io/v1beta1
kind: ProviderConfig
metadata:
name: default
spec:
credentials:
source: Secret
secretRef:
namespace: crossplane-system
name: aws-secret
key: credentials
EOF
# get config
loadenv ./.env
# deploy hub
waitfor default crd hubs.backstack.cncf.io
kubectl wait crd/hubs.backstack.cncf.io --for=condition=Established --timeout=1m
kubectl apply -f - <<-EOF
apiVersion: backstack.cncf.io/v1alpha1
kind: Hub
metadata:
name: hub
spec:
parameters:
clusterId: local
repository: ${REPOSITORY}
backstage:
host: backstage-7f000001.nip.io
argocd:
host: argocd-7f000001.nip.io
vault:
host: vault-7f000001.nip.io
EOF
# deploy secrets
waitfor default ns argocd
kubectl create -f - <<-EOF
apiVersion: v1
kind: Secret
metadata:
name: clusters
namespace: argocd
labels:
argocd.argoproj.io/secret-type: repository
stringData:
type: git
url: ${REPOSITORY}
password: ${GITHUB_TOKEN}
username: back-stack
EOF
waitfor default ns backstage
kubectl create -f - <<-EOF
apiVersion: v1
kind: Secret
metadata:
name: backstage
namespace: backstage
stringData:
GITHUB_TOKEN: ${GITHUB_TOKEN}
VAULT_TOKEN: ${VAULT_TOKEN}
EOF
kubectl create -f - <<-EOF
apiVersion: v1
kind: Secret
metadata:
name: azure-secret
namespace: crossplane-system
stringData:
credentials: |
${AZURE_CREDENTIALS}
EOF
kubectl create -f - <<-EOF
apiVersion: v1
kind: Secret
metadata:
name: aws-secret
namespace: crossplane-system
stringData:
credentials: |
[default]
aws_access_key_id=${AWS_ACCESS_KEY_ID}
aws_secret_access_key=${AWS_SECRET_ACCESS_KEY}
aws_session_token=${AWS_SESSION_TOKEN}
EOF
waitfor argocd secret argocd-initial-admin-secret
ARGO_INITIAL_PASSWORD=$(kubectl get secret -n argocd argocd-initial-admin-secret -o jsonpath='{.data.password}' | base64 -d)
# configure vault
kubectl wait -n vault pod/vault-0 --for=condition=Ready --timeout=1m
kubectl -n vault exec -i vault-0 -- vault auth enable kubernetes
kubectl -n vault exec -i vault-0 -- sh -c 'vault write auth/kubernetes/config \
token_reviewer_jwt="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" \
kubernetes_host="https://$KUBERNETES_PORT_443_TCP_ADDR:443" \
kubernetes_ca_cert=@/var/run/secrets/kubernetes.io/serviceaccount/ca.crt'
kubectl -n vault exec -i vault-0 -- vault policy write crossplane - <<EOF
path "secret/data/*" {
capabilities = ["create", "read", "update", "delete"]
}
path "secret/metadata/*" {
capabilities = ["create", "read", "update", "delete"]
}
EOF
kubectl -n vault exec -i vault-0 -- vault write auth/kubernetes/role/crossplane \
bound_service_account_names="*" \
bound_service_account_namespaces=crossplane-system \
policies=crossplane \
ttl=24h
# restart ess pod
kubectl get -n crossplane-system pods -o name | grep ess-plugin-vault | xargs kubectl delete -n crossplane-system
# ready to go!
echo ""
echo "
Your BACK Stack is ready!
Backstage: https://backstage-7f000001.nip.io
ArgoCD: https://argocd-7f000001.nip.io
username: admin
password ${ARGO_INITIAL_PASSWORD}
"