-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathkubectl-apply.sh
55 lines (44 loc) · 1.32 KB
/
kubectl-apply.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
#!/bin/bash
# Files are ordered in proper order with needed wait for the dependent custom resource definitions to get initialized.
# Usage: bash kubectl-apply.sh
usage(){
cat << EOF
Usage: $0 -f
Description: To apply k8s manifests using the default \`kubectl apply -f\` command
[OR]
Usage: $0 -k
Description: To apply k8s manifests using the kustomize \`kubectl apply -k\` command
[OR]
Usage: $0 -s
Description: To apply k8s manifests using the skaffold binary \`skaffold run\` command
EOF
exit 0
}
init() {
kubectl create secret generic bounties-mysql-secret --from-literal=username=root --from-literal=password=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16)
}
logSummary() {
echo ""
}
default() {
kubectl apply -f kubernetes/
}
kustomize() {
kubectl apply -k ./
}
scaffold() {
// this will build the source and apply the manifests the K8s target. To turn the working directory
// into a CI/CD space, initilaize it with `skaffold dev`
skaffold run
}
[[ "$@" =~ ^-[fks]{1}$ ]] || usage;
while getopts ":fks" opt; do
init
case ${opt} in
f ) echo "Applying default \`kubectl apply -f\`"; default ;;
k ) echo "Applying kustomize \`kubectl apply -k\`"; kustomize ;;
s ) echo "Applying using skaffold \`skaffold run\`"; scaffold ;;
\? | * ) usage ;;
esac
done
logSummary