github.com/SamarSidharth/kpt@v0.0.0-20231122062228-c7d747ae3ace/site/guides/porch-installation.md (about)

     1  # Installing Porch
     2  
     3  You can install Porch by either using one of the
     4  [released versions](https://github.com/GoogleContainerTools/kpt/releases), or
     5  building Porch from sources.
     6  
     7  ## Prerequisites
     8  
     9  Note: Porch should run on any kubernetes cluster and should work on any cloud.
    10  We have just started by documenting one known-good configuration: GCP and GKE.
    11  We would welcome comparable installation instructions or feedback from people
    12  that try it out on other clouds / configurations.
    13  
    14  To run one of the [released versions](https://github.com/GoogleContainerTools/kpt/releases)
    15  of Porch on GKE, you will need:
    16  
    17  * A [GCP Project](https://console.cloud.google.com/projectcreate)
    18  * [gcloud](https://cloud.google.com/sdk/docs/install)
    19  * [kubectl](https://kubernetes.io/docs/tasks/tools/); you can install it via
    20    `gcloud components install kubectl`
    21  * [kpt](https://kpt.dev/)
    22  * Command line utilities such as `curl`, `tar`
    23  
    24  To build and run Porch on GKE, you will also need:
    25  
    26  * A container registry which will work with your GKE cluster.
    27    [Artifact Registry](https://console.cloud.google.com/artifacts)
    28    or [Container Registry](https://console.cloud.google.com/gcr) work well
    29    though you can use others too.
    30  * [go 1.17](https://go.dev/dl/) or newer
    31  * [docker](https://docs.docker.com/get-docker/)
    32  * [Configured docker credential helper](https://cloud.google.com/sdk/gcloud/reference/auth/configure-docker)
    33  * [git](https://git-scm.com/)
    34  * [make](https://www.gnu.org/software/make/)
    35  
    36  ## Getting Started
    37  
    38  Make sure your `gcloud` is configured with your project (alternatively, you can
    39  augment all following `gcloud` commands below with `--project` flag):
    40  
    41  ```sh
    42  gcloud config set project YOUR_GCP_PROJECT
    43  ```
    44  
    45  Select a GKE cluster or create a new one:
    46  
    47  ```sh
    48  gcloud services enable container.googleapis.com
    49  gcloud container clusters create-auto --region us-central1 porch-dev
    50  ```
    51  
    52  **Note:** For development of Porch, in particular for running Porch tests,
    53  Standard GKE cluster is currently preferable. Select a
    54  [GCP region](https://cloud.google.com/compute/docs/regions-zones#available)
    55   that works best for your needs:
    56  
    57   ```sh
    58  gcloud services enable container.googleapis.com
    59  gcloud container clusters create --region us-central1 porch-dev
    60  ```
    61  
    62  And ensure `kubectl` is targeting your GKE cluster:
    63  
    64  ```sh
    65  gcloud container clusters get-credentials --region us-central1 porch-dev
    66  ```
    67  
    68  ## Run Released Version of Porch
    69  
    70  To run a released version of Porch, download the release config bundle from
    71  [Porch release page](https://github.com/GoogleContainerTools/kpt/releases);
    72  please note you'll need to scroll past recent kpt releases to the most
    73  recent `porch/...` release.
    74  
    75  Untar and apply the `deployment-blueprint.tar.gz` config bundle. This will install:
    76  
    77  * Porch server
    78  * [Config Sync](https://kpt.dev/gitops/configsync/)
    79  
    80  ```sh
    81  mkdir porch-install
    82  tar xzf ~/Downloads/deployment-blueprint.tar.gz -C porch-install
    83  kubectl apply -f porch-install
    84  kubectl wait deployment --for=condition=Available porch-server -n porch-system
    85  ```
    86  
    87  You can verify that Porch is running by querying the `api-resources`:
    88  
    89  ```sh
    90  kubectl api-resources | grep porch
    91  ```
    92  Expected output will include:
    93  
    94  ```
    95  repositories                                   config.porch.kpt.dev/v1alpha1          true         Repository
    96  functions                                      porch.kpt.dev/v1alpha1                 true         Function
    97  packagerevisionresources                       porch.kpt.dev/v1alpha1                 true         PackageRevisionResources
    98  packagerevisions                               porch.kpt.dev/v1alpha1                 true         PackageRevision
    99  ```
   100  
   101  To install ConfigSync:
   102  
   103  ```sh
   104  echo "
   105  apiVersion: configmanagement.gke.io/v1
   106  kind: ConfigManagement
   107  metadata:
   108    name: config-management
   109  spec:
   110    enableMultiRepo: true
   111  " | kubectl apply -f -
   112  ```
   113  
   114  You can start [using Porch](guides/porch-user-guide.md).
   115  
   116  ## Run Custom Build of Porch
   117  
   118  To run custom build of Porch, you will need additional [prerequisites](#prerequisites).
   119  The commands below use [Google Container Registry](https://console.cloud.google.com/gcr).
   120  
   121  Clone this repository into `${GOPATH}/src/github.com/GoogleContainerTools/kpt`.
   122  
   123  ```sh
   124  git clone https://github.com/GoogleContainerTools/kpt.git "${GOPATH}/src/github.com/GoogleContainerTools/kpt"
   125  ```
   126  
   127  [Configure](https://cloud.google.com/sdk/gcloud/reference/auth/configure-docker)
   128  docker credential helper for your repository
   129  
   130  If your use case doesn't require Porch to interact with GCP container registries,
   131  you can build and deploy Porch by running the following command. It will build and
   132  push Porch Docker images into (by default) Google Container Registry named (example
   133  shown is the Porch server image):
   134  
   135  `gcr.io/YOUR-PROJECT-ID/porch-server:SHORT-COMMIT-SHA`
   136  
   137  
   138  ```sh
   139  IMAGE_TAG=$(git rev-parse --short HEAD) make push-and-deploy-no-sa
   140  ```
   141  
   142  If you want to use different repository, you can set `IMAGE_REPO` variable
   143  (see [Makefile](https://github.com/GoogleContainerTools/kpt/blob/main/porch/Makefile#L28)
   144  for details).
   145  
   146  The `make push-and-deploy-no-sa` target will install Porch but not Config Sync.
   147  You can install Config Sync in your k8s cluster manually following the
   148  [documentation](https://github.com/GoogleContainerTools/kpt-config-sync/blob/main/docs/installation.md).
   149  
   150  **Note**: The `-no-sa` (no service account) targets create Porch deployment
   151  configuration which does not associate Kubernetes service accounts with GCP
   152  service accounts. This is sufficient for Porch to integate with Git repositories
   153  using Basic Auth, for example GitHub.
   154  
   155  As above, you can verify that Porch is running by querying the `api-resources`:
   156  
   157  ```sh
   158  kubectl api-resources | grep porch
   159  ```
   160  
   161  And start [using Porch](guides/porch-user-guide.md) if the Porch resources are
   162  available.
   163  
   164  ### Workload Identity
   165  
   166  [Workload Identity](https://cloud.google.com/kubernetes-engine/docs/concepts/workload-identity)
   167  is a simple way to access Google Cloud services from porch.
   168  
   169  #### Google Cloud Source Repositories
   170  
   171  [Cloud Source Repositories](https://cloud.google.com/source-repositories) can be access using
   172  workload identity, removing the need to store credentials in the cluster.
   173  
   174  To set it up, create the necessary service accounts and give it the required roles:
   175  
   176  ```sh
   177  GCP_PROJECT_ID=$(gcloud config get-value project)
   178  
   179  # Create GCP service account (GSA) for Porch server.
   180  gcloud iam service-accounts create porch-server
   181  
   182  # We want to create and delete images. Assign IAM roles to allow repository
   183  # administration.
   184  gcloud projects add-iam-policy-binding ${GCP_PROJECT_ID} \
   185    --member "serviceAccount:porch-server@${GCP_PROJECT_ID}.iam.gserviceaccount.com" \
   186    --role "roles/source.admin"
   187  
   188  gcloud iam service-accounts add-iam-policy-binding porch-server@${GCP_PROJECT_ID}.iam.gserviceaccount.com \
   189    --role roles/iam.workloadIdentityUser \
   190    --member "serviceAccount:${GCP_PROJECT_ID}.svc.id.goog[porch-system/porch-server]"
   191  
   192  # We need to associate the Kubernetes Service Account (KSA)
   193  # with the GSA by annotating the KSA.
   194  kubectl annotate serviceaccount porch-server -n porch-system \
   195    iam.gke.io/gcp-service-account=porch-server@${GCP_PROJECT_ID}.iam.gserviceaccount.com
   196  ```
   197  
   198  Build Porch, push images, and deploy porch server and controllers using the
   199  `make` target that adds workload identity service account annotations:
   200  
   201  ```sh
   202  IMAGE_TAG=$(git rev-parse --short HEAD) make push-and-deploy
   203  ```
   204  
   205  As above, you can verify that Porch is running by querying the `api-resources`:
   206  
   207  ```sh
   208  kubectl api-resources | grep porch
   209  ```
   210  
   211  To register a repository, use the following command:
   212  ```sh
   213  kpt alpha repo register --repo-workload-identity --namespace=default https://source.developers.google.com/p/<project>/r/<repo>
   214  ```
   215  
   216  #### OCI
   217  
   218  To integrate with OCI repositories such as
   219  [Artifact Registry](https://console.cloud.google.com/artifacts) or
   220  [Container Registry](https://console.cloud.google.com/gcr), Porch relies on
   221  [workload identity](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity).
   222  
   223  For that use case, create service accounts and assign roles:
   224  
   225  ```sh
   226  GCP_PROJECT_ID=$(gcloud config get-value project)
   227  
   228  # Create GCP service account for Porch server.
   229  gcloud iam service-accounts create porch-server
   230  # Create GCP service account for Porch sync controller.
   231  gcloud iam service-accounts create porch-sync
   232  
   233  # We want to create and delete images. Assign IAM roles to allow repository
   234  # administration.
   235  gcloud projects add-iam-policy-binding ${GCP_PROJECT_ID} \
   236    --member "serviceAccount:porch-server@${GCP_PROJECT_ID}.iam.gserviceaccount.com" \
   237    --role "roles/artifactregistry.repoAdmin"
   238  
   239  gcloud iam service-accounts add-iam-policy-binding porch-server@${GCP_PROJECT_ID}.iam.gserviceaccount.com \
   240    --role roles/iam.workloadIdentityUser \
   241    --member "serviceAccount:${GCP_PROJECT_ID}.svc.id.goog[porch-system/porch-server]"
   242  
   243  gcloud projects add-iam-policy-binding ${GCP_PROJECT_ID} \
   244    --member "serviceAccount:porch-sync@${GCP_PROJECT_ID}.iam.gserviceaccount.com" \
   245    --role "roles/artifactregistry.reader"
   246  
   247  gcloud iam service-accounts add-iam-policy-binding porch-sync@${GCP_PROJECT_ID}.iam.gserviceaccount.com \
   248    --role roles/iam.workloadIdentityUser \
   249    --member "serviceAccount:${GCP_PROJECT_ID}.svc.id.goog[porch-system/porch-controllers]"
   250  ```
   251  
   252  Build Porch, push images, and deploy porch server and controllers using the
   253  `make` target that adds workload identity service account annotations:
   254  
   255  ```sh
   256  IMAGE_TAG=$(git rev-parse --short HEAD) make push-and-deploy
   257  ```
   258  
   259  As above, you can verify that Porch is running by querying the `api-resources`:
   260  
   261  ```sh
   262  kubectl api-resources | grep porch
   263  ```
   264  
   265  And start [using Porch](guides/porch-user-guide.md) if the Porch resources are
   266  available.