-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathiac.environmaen.sh
114 lines (78 loc) · 3.65 KB
/
iac.environmaen.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
# Install Homebrew
yes|/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"&&eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
# Install Terraform, Flux, and htop using Homebrew
yes|brew install opentofu fluxcd/tap/flux kind derailed/k9s/k9s age sops
# Initialize kind cluster
cat <<EOF >> kind-config.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
EOF
#
kind create cluster --config kind-config.yaml
# Create alias for kubectl and command-line autocompletion
alias k=kubectl
# Enable kubectl and Flux command-line autocompletion for Zsh
. <(kubectl completion zsh)
. <(flux completion zsh)
# Install flux and tf-controller
flux install
# Create a HelmRepository and HelmRelease resources for the tf-controller Helm chart
flux create source helm tf-controller --url=oci://ghcr.io/flux-iac/charts --interval=1h0s -n flux-system --export
flux create source helm tf-controller --url=oci://ghcr.io/flux-iac/charts --interval=1h0s -n flux-system
# Create helm release tf-controller
flux create source helm tf-controller --url=oci://ghcr.io/flux-iac/charts --interval=1h0s -n flux-system
flux create hr tf-controller -n flux-system --interval=5m --source=HelmRepository/tf-controller --chart=tf-controller --chart-version="0.16.0-rc.4" --crds CreateReplace
## Explore terrafrom code for tls keys module
https://github.com/den-vasyliev/fwdays-workshop/blob/tf-controller/tf-gke-cluster/tf-tls-keys-gr.yaml
https://github.com/den-vasyliev/tf-hashicorp-tls-keys
## terrafrom CR
https://github.com/den-vasyliev/fwdays-workshop/blob/tf-controller/tf-gke-cluster/tls-keys-tf.yaml
## Explore terrafrom code for GKE cluster with gpu
https://github.com/den-vasyliev/fwdays-workshop/blob/tf-controller/tf-gke-cluster/main.tf
# Prepare the SOPS secret
## Generate a new age key
age-keygen -o ~/.ssh/age-key.txt
## Create a Kubernetes secret for the age key
cat ~/.ssh/age-key.txt |
k create secret generic sops-age \
--namespace=flux-system \
--from-file=age.agekey=/dev/stdin
## Export the public key
AGE_PUB_KEY=age1lxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Create a Kubernetes secret for GCP authentication
## Create service account
## Create a service account key
## Create a Kubernetes secret for the service account key
k create secret -n flux-system generic k8s-k3s-secret --from-file=credentials=../../GCP_PROJECT.json -o yaml --dry-run=client>gcp-auth-secret.yaml
## Encrypt the secret using SOPS and the age key
sops --age=$AGE_PUB_KEY --encrypt --encrypted-regex '^(data|stringData)$' --in-place gcp-auth-secret.yaml
## Enable decription in flux with kustomization.yaml patch
decryption:
provider: sops
secretRef:
name: sops-age
# Terraform with GitOps
## Create git source for the tf-config repository
flux create source git tf-config -n flux-system --url=https://github.com/den-vasyliev/fwdays-workshop --branch=tf-controller --interval=5m --export
## Create kustomization for the tf-config repository
flux bootstrap git \
--url=https://github.com/den-vasyliev/fwdays-workshop \
--branch=tf-controller \
--path=tf-gke-cluster \
--token-auth
k get tf -A
## Bootstrap the ollama setup on new cluster
# finally apply
# flux create source git ollama -n default --url=https://github.com/den-vasyliev/fw-non-prod --branch=main --interval=5m --export
# flux create source git ollama -n default --url=https://github.com/den-vasyliev/fw-non-prod --branch=main --interval=5m
# On new cluster
flux bootstrap git \
--url=https://github.com/den-vasyliev/fw-non-prod \
--branch=main \
--path=clusters/my-cluster \
--token-auth --export
flux get all -A --status-selector ready=false