11# Running on GKE
22
3- Create a GKE cluster:
3+ ## Prerequisites
44
5- ** Note** : We need the release-channel=rapid as we depend on k8s 1.22 (because of priority and fairness APIs moving to beta2)
5+ To run one of the [ released versions] ( https://github.com/GoogleContainerTools/kpt/releases )
6+ of Porch on GKE, you will need:
7+
8+ * A [ GCP Project] ( https://console.cloud.google.com/projectcreate )
9+ * [ gcloud] ( https://cloud.google.com/sdk/docs/install )
10+ * [ kubectl] ( https://kubernetes.io/docs/tasks/tools/ ) ; you can install it via
11+ ` gcloud components install kubectl `
12+ * [ kpt] ( https://kpt.dev/ )
13+ * Command line utilities such as ` curl ` , ` tar `
14+
15+ To build and run Porch on GKE, you will also need:
16+
17+ * A container registry which will work with your GKE cluster.
18+ [ Artifact Registry] ( https://console.cloud.google.com/artifacts )
19+ or [ Container Registry] ( https://console.cloud.google.com/gcr ) work well
20+ though you can use others too.
21+ * [ go 1.17] ( https://go.dev/dl/ ) or newer
22+ * [ docker] ( https://docs.docker.com/get-docker/ )
23+ * [ Configured docker credential helper] ( https://cloud.google.com/sdk/gcloud/reference/auth/configure-docker )
24+ * [ git] ( https://git-scm.com/ )
25+ * [ make] ( https://www.gnu.org/software/make/ )
26+
27+ ## Getting Started
28+
29+ Make sure your ` gcloud ` is configured with your project (alternatively, you can
30+ augment all following ` gcloud ` commands below with ` --project ` flag):
31+
32+ ``` sh
33+ gcloud config set project YOUR_GCP_PROJECT
34+ ```
35+
36+ Select a GKE cluster or create a new one:
637
738``` sh
8- gcloud container clusters create-auto --region us-central1 --release-channel=rapid porch-dev
39+ gcloud container clusters create-auto --region us-central1 porch-dev
40+ ```
41+
42+ ** Note:** For development of Porch, in particular for running Porch tests,
43+ Standard GKE cluster is currently preferable. Select a
44+ [ GCP region] ( https://cloud.google.com/compute/docs/regions-zones#available )
45+ that works best for your needs:
46+
47+ ``` sh
48+ gcloud container clusters create --region us-central1 porch-dev
949```
1050
11- Ensure you are targeting the GKE cluster:
51+ And ensure ` kubectl ` is targeting your GKE cluster:
52+
53+ Ensure you are targeting the GKE cluster. Make sure to substitute your
54+ specific region and cluster name:
55+
1256``` sh
1357gcloud container clusters get-credentials --region us-central1 porch-dev
1458```
1559
16- Create service accounts and assign roles:
60+ ## Run Released Version of Porch
61+
62+ To run a released version of Porch, download the release config bundle from
63+ [ Porch release page] ( https://github.com/GoogleContainerTools/kpt/releases ) .
64+
65+ Untar and applly the config bundle. This will install:
66+
67+ * Porch server
68+ * [ Config Sync] ( https://cloud.google.com/anthos-config-management/docs/config-sync-overview )
69+
70+ ``` sh
71+ mkdir porch-install
72+ tar xzf path-to-deployment-blueprint.tar.gz -C porch-install
73+ kubectl apply -f porch-install
74+ ```
75+
76+ You can verify that Porch is running by querying the ` api-resources ` :
77+
78+ ``` sh
79+ kubectl api-resources | grep porch
80+ ```
81+ Expected output will include:
82+
83+ ```
84+ repositories config.porch.kpt.dev/v1alpha1 true Repository
85+ functions porch.kpt.dev/v1alpha1 true Function
86+ packagerevisionresources porch.kpt.dev/v1alpha1 true PackageRevisionResources
87+ packagerevisions porch.kpt.dev/v1alpha1 true PackageRevision
88+ ```
89+
90+ You can start [ using Porch] ( ../README.md#using-porch ) .
91+
92+ ## Run Custom Build of Porch
93+
94+ To run custom build of Porch, you will need additional [ prerequisites] ( #prerequisites ) .
95+ The commands below use [ Google Container Registry] ( https://console.cloud.google.com/gcr ) .
96+
97+ Clone this repository into ` ${GOPATH}/src/github.com/GoogleContainerTools/kpt ` .
98+
99+ ``` sh
100+ git clone https://github.com/GoogleContainerTools/kpt.git " ${GOPATH} /src/github.com/GoogleContainerTools/kpt"
101+ ```
102+
103+ [ Configure] ( https://cloud.google.com/sdk/gcloud/reference/auth/configure-docker )
104+ docker credential helper for your repository
105+
106+ If your use case doesn't require Porch to interact with GCP container registries,
107+ you can build and deploy Porch by running the following command. It will build and
108+ push Porch Docker images into (by default) Google Container Registry named (example
109+ shown is the Porch server image):
110+
111+ ` gcr.io/YOUR-PROJECT-ID/porch-server:SHORT-COMMIT-SHA `
112+
113+
114+ ``` sh
115+ IMAGE_TAG=$( git rev-parse --short HEAD) make push-and-deploy-no-sa
116+ ```
117+
118+ If you want to use different repository, you can set ` IMAGE_REPO ` variable
119+ (see [ Makefile] ( https://github.com/GoogleContainerTools/kpt/blob/main/porch/Makefile#L28 )
120+ for details).
121+
122+ The ` make push-and-deploy-no-sa ` target will install Porch but not Config Sync.
123+ You can install Config Sync in your k8s cluster manually following the
124+ [ documentation] ( https://cloud.google.com/anthos-config-management/docs/how-to/installing-kubectl ) .
125+
126+ ** Note** : The ` -no-sa ` (no service account) targets create Porch deployment
127+ configuration which does not associate Kubernetes service accounts with GCP
128+ service accounts. This is sufficient for Porch to integate with Git repositories
129+ using Basic Auth, for example GitHub.
130+
131+ As above, you can verify that Porch is running by querying the ` api-resources ` :
132+
133+ ``` sh
134+ kubectl api-resources | grep porch
135+ ```
136+
137+ And start [ using Porch] ( ../README.md#using-porch ) if the Porch resources are
138+ available.
139+
140+ ### Workload Identity
141+
142+ To integrate with OCI repositories such as
143+ [ Artifact Registry] ( https://console.cloud.google.com/artifacts ) or
144+ [ Container Registry] ( https://console.cloud.google.com/gcr ) , Porch relies on
145+ [ workload identity] ( https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity ) .
146+
147+ For that use case, create service accounts and assign roles:
17148
18149``` sh
19150GCP_PROJECT_ID=$( gcloud config get-value project)
151+
152+ # Create GCP service account for Porch server.
20153gcloud iam service-accounts create porch-server
154+ # Create GCP service account for Porch sync controller.
21155gcloud iam service-accounts create porch-sync
22156
23- # We want to create and delete images
157+ # We want to create and delete images. Assign IAM roles to allow repository
158+ # administration.
24159gcloud projects add-iam-policy-binding ${GCP_PROJECT_ID} \
25- --member " serviceAccount:porch-server@${GCP_PROJECT_ID} .iam.gserviceaccount.com" \
26- --role " roles/artifactregistry.repoAdmin"
160+ --member " serviceAccount:porch-server@${GCP_PROJECT_ID} .iam.gserviceaccount.com" \
161+ --role " roles/artifactregistry.repoAdmin"
162+
27163gcloud iam service-accounts add-iam-policy-binding porch-server@${GCP_PROJECT_ID} .iam.gserviceaccount.com \
28- --role roles/iam.workloadIdentityUser \
29- --member " serviceAccount:${GCP_PROJECT_ID} .svc.id.goog[porch-system/porch-server]"
164+ --role roles/iam.workloadIdentityUser \
165+ --member " serviceAccount:${GCP_PROJECT_ID} .svc.id.goog[porch-system/porch-server]"
30166
31167gcloud projects add-iam-policy-binding ${GCP_PROJECT_ID} \
32- --member " serviceAccount:porch-sync@${GCP_PROJECT_ID} .iam.gserviceaccount.com" \
33- --role " roles/artifactregistry.reader"
168+ --member " serviceAccount:porch-sync@${GCP_PROJECT_ID} .iam.gserviceaccount.com" \
169+ --role " roles/artifactregistry.reader"
170+
34171gcloud iam service-accounts add-iam-policy-binding porch-sync@${GCP_PROJECT_ID} .iam.gserviceaccount.com \
35- --role roles/iam.workloadIdentityUser \
36- --member " serviceAccount:${GCP_PROJECT_ID} .svc.id.goog[porch-system/porch-controllers]"
172+ --role roles/iam.workloadIdentityUser \
173+ --member " serviceAccount:${GCP_PROJECT_ID} .svc.id.goog[porch-system/porch-controllers]"
37174```
38175
39- Build Porch, push images, and deploy porch server and controllers:
176+ Build Porch, push images, and deploy porch server and controllers using the
177+ ` make ` target that adds workload identity service account annotations:
40178
41179``` sh
42180IMAGE_TAG=$( git rev-parse --short HEAD) make push-and-deploy
43181```
44182
183+ As above, you can verify that Porch is running by querying the ` api-resources ` :
184+
185+ ``` sh
186+ kubectl api-resources | grep porch
187+ ```
188+
189+ And start [ using Porch] ( ../README.md#using-porch ) if the Porch resources are
190+ available.
191+
192+ ## Deploying Configuration
193+
194+ ** Note:** Rather than using Config Sync, this section uses a prototype sync
195+ controller.
196+
45197Create some example repositories / packages:
46198
47199``` sh
@@ -60,5 +212,6 @@ To test out remoterootsync self-applying:
60212kubectl apply -f controllers/remoterootsync/config/samples/hack-self-apply-rbac.yaml
61213
62214# Apply the RemoteRootSyncSet
63- cat controllers/remoterootsync/config/samples/hack-self-apply.yaml | sed -e s/example-google-project-id/${GCP_PROJECT_ID} /g | kubectl apply -f -
215+ cat controllers/remoterootsync/config/samples/hack-self-apply.yaml \
216+ | sed -e s/example-google-project-id/${GCP_PROJECT_ID} /g | kubectl apply -f -
64217```
0 commit comments