Creating VPC Peering in Google Cloud ​
This tutorial explains how to create a Virtual Private Cloud (VPC) peering connection between a remote VPC network and SAP BTP, Kyma runtime in Google Cloud.
Prerequisites ​
- You have the Cloud Manager module added. See Add and Delete a Kyma Module.
- Google Cloud CLI
NOTE
Use a POSIX-compliant shell or adjust the commands accordingly. For example, if you use Windows, replace the export commands with set and use % before and after the environment variables names.
Steps ​
Authorize Cloud Manager in the Remote Project ​
To create a VPC peering connection, certain permissions are required in the remote project. The recommended approach is creating a role and assigning it to the Cloud Manager service account.
Export your remote project ID and desired role name as an environment variable.
shellexport YOUR_REMOTE_PROJECT_ID={YOUR_REMOTE_PROJECT_ID} export ROLE_NAME=peeringWithKymaCreate a custom role with the required permissions.
shellgcloud iam roles create $ROLE_NAME --permissions="compute.networks.addPeering,compute.networks.get,compute.networks.listEffectiveTags" --project=$YOUR_REMOTE_PROJECT_ID --quietSee Authorizing Cloud Manager in the Remote Cloud Provider and assign the custom role created on the previous step to the correct Cloud Manager service account for your environment. The following example shows how to assign the role in a production environment.
shellgcloud projects add-iam-policy-binding $YOUR_REMOTE_PROJECT_ID --member=serviceAccount:cloud-manager-peering@sap-ti-dx-kyma-mps-prod.iam.gserviceaccount.com --role=projects/$YOUR_REMOTE_PROJECT_ID/roles/$ROLE_NAME
Allow SAP BTP, Kyma Runtime to Peer with Your Network ​
Due to security reasons, the VPC network in the remote project, which receives the VPC peering connection, must contain a tag with the Kyma shoot name.
Fetch your Kyma ID and export it as an environment variable.
shellexport KYMA_SHOOT_ID=`kubectl get cm -n kube-system shoot-info -o jsonpath='{.data.shootName}'`Export your VPC network name to an environment variable.
shellexport REMOTE_VPC_NETWORK={REMOTE_VPC_NETWORK}Create a tag key with the Kyma shoot name in the remote project.
shellgcloud resource-manager tags keys create $KYMA_SHOOT_ID --parent=projects/$YOUR_REMOTE_PROJECT_IDCreate a tag value in the remote project.
shellexport TAG_VALUE=None gcloud resource-manager tags values create $TAG_VALUE --parent=$YOUR_REMOTE_PROJECT_ID/$KYMA_SHOOT_IDFetch the network
selfLinkWithIdfrom the remote VPC network.shellgcloud compute networks describe $REMOTE_VPC_NETWORKThe command returns an output similar to this one:
shell... routingConfig: routingMode: REGIONAL selfLink: https://www.googleapis.com/compute/v1/projects/remote-project-id/global/networks/remote-vpc selfLinkWithId: https://www.googleapis.com/compute/v1/projects/remote-project-id/global/networks/1234567890123456789 subnetworks: - https://www.googleapis.com/compute/v1/projects/remote-project-id/regions/europe-west12/subnetworks/remote-vpc ...Export resource ID as an environment variable. Use the value of
selfLinkWithIdreturned in the previous command's output, but replacehttps://www.googleapis.com/compute/v1with//compute.googleapis.com.shellexport RESOURCE_ID="//compute.googleapis.com/projects/remote-project-id/global/networks/1234567890123456789"Add the tag to the VPC network.
shellgcloud resource-manager tags bindings create --tag-value=$YOUR_REMOTE_PROJECT_ID/$KYMA_SHOOT_ID/$TAG_VALUE --parent=$RESOURCE_ID
Create VPC Peering ​
Create a GcpVpcPeering resource manifest file similar to the following example, replacing
my-project-to-kyma-dev,remote-project-id, andremote-vpc-networkwith your desired peering name, remote project ID, and remote VPC network, respectively. And save it asvpc-peering.yaml.shellapiVersion: cloud-resources.kyma-project.io/v1beta1 kind: GcpVpcPeering metadata: name: "vpcpeering-dev" spec: remotePeeringName: "my-project-to-kyma-dev" remoteProject: "remote-project-id" remoteVpc: "remote-vpc-network" importCustomRoutes: falseApply the manifest file.
shellkubectl apply -f vpc-peering.yamlThis operation usually takes less than 2 minutes. To check the status of the VPC peering, run:
shellkubectl get gcpvpcpeering vpcpeering-dev -o yamlThe command returns an output similar to this one:
yamlapiVersion: cloud-resources.kyma-project.io/v1beta1 kind: GcpVpcPeering finalizers: - cloud-control.kyma-project.io/deletion-hook generation: 2 name: vpcpeering-dev resourceVersion: "12345678" uid: 8545cdaa-66d3-4fa7-b20b-7c716148552f spec: remotePeeringName: my-project-to-kyma-dev remoteProject: remote-project-id remoteVpc: remote-vpc-network status: conditions: - lastTransitionTime: "2024-08-12T15:29:59Z" message: VpcPeering: my-project-to-kyma-dev is provisioned reason: Ready status: "True" type: ReadyThe status.conditions field contains information about the VPC Peering status.
Next Steps ​
When the VPC peering is not needed anymore, you can remove it.
Delete the GcpVpcPeering resource from your Kyma cluster. This operation can take a few minutes to complete.
shellkubectl delete gcpvpcpeering vpcpeering-devRemove the inactive VPC peering from the remote project.
shellgcloud compute networks peerings delete my-project-to-kyma-dev --network=remote-vpc-network --project=remote-project-id