Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to add a path rule to an existing path matcher of a URL map?

I have the following URL map:

 

 

 

creationTimestamp: '2024-08-26T10:11:04.884-07:00'
defaultService: https://www.googleapis.com/compute/v1/projects/xxxxxxx/global/backendBuckets/cats
fingerprint: MVSuBQdJvxM=
hostRules:
- hosts:
  - '*'
  pathMatcher: path-matcher-pets
id: 'xxx'
kind: compute#urlMap
name: http-lb
pathMatchers:
- defaultService: https://www.googleapis.com/compute/v1/projects/xxxxxxxx/global/backendBuckets/cats
  name: path-matcher-pets
selfLink: https://www.googleapis.com/compute/v1/projects/storage-buckets-432513/global/urlMaps/http-lb

 

 

 

I need to add a backend-bucket-path-rule so that i achieve the folllowing state of the URL map:

 

 

 

creationTimestamp: '2024-08-26T10:11:04.884-07:00'
defaultService: https://www.googleapis.com/compute/v1/projects/xxxx/global/backendBuckets/cats
fingerprint: xxx
hostRules:
- hosts:
  - '*'
  pathMatcher: path-matcher-pets
id: 'xxx'
kind: compute#urlMap
name: http-lb
pathMatchers:
- defaultService: https://www.googleapis.com/compute/v1/projects/xxxx/global/backendBuckets/cats
  name: path-matcher-pets
  pathRules:
  - paths:
    - /love-to-fetch/*
    service: https://www.googleapis.com/compute/v1/projects/xxxxx/global/backendBuckets/dogs
selfLink: https://www.googleapis.com/compute/v1/projects/xxxx/global/urlMaps/http-lb

 

 

 

How can i accomplish this. How can i add a path rule `love-to-fetch` to the existing patch matcher `path-matcher-pets`?

I am looking at the following reference documentation, but i can't see a way to edit the path matcher:
https://cloud.google.com/sdk/gcloud/reference/compute/url-maps/add-path-matcher#--backend-bucket-pat...

 

 

Solved Solved
0 2 726
1 ACCEPTED SOLUTION

Hi @mountaincode2,

Welcome to Google Cloud Community!

We can add backend-bucket-path-rule to an existing path matcher by editing your load balancer via console:

Step 1: Go to Backend configuration and create a Backend Bucket

Screenshot 2024-08-30 2.43.17 AM.png

Step 2: On the routing rules add Path rule /love-to-fetch/* then click update.

Screenshot 2024-08-30 2.55.24 AM.png

Another way to do this is via Vi Editor on your cloudshell, assuming that backend bucket is already created:

 Step 1: Run

 

gcloud compute url-maps list

 

  Step 2: Edit Load Balancer: gcloud compute url-maps edit [name of your Load Balancer] 

              Example: 

 

gcloud compute url-maps edit http-lb

 

  Step 3: Press ito insert additional pathrule

  Step 4: Add the new pathrule:

             Example: 

 

name: path-matcher-2
  pathRules:
  - paths:
    - /love-to-fetch/*
    - /never-fetch/*
    - /love-to-fly/*

 

Step 5: Press esc, then ctrl + : and type wq! to save and quit. Press Enter.

References: 

url-maps list,

url-maps edit

I hope the above information is helpful.

View solution in original post

2 REPLIES 2

Hi @mountaincode2,

Welcome to Google Cloud Community!

We can add backend-bucket-path-rule to an existing path matcher by editing your load balancer via console:

Step 1: Go to Backend configuration and create a Backend Bucket

Screenshot 2024-08-30 2.43.17 AM.png

Step 2: On the routing rules add Path rule /love-to-fetch/* then click update.

Screenshot 2024-08-30 2.55.24 AM.png

Another way to do this is via Vi Editor on your cloudshell, assuming that backend bucket is already created:

 Step 1: Run

 

gcloud compute url-maps list

 

  Step 2: Edit Load Balancer: gcloud compute url-maps edit [name of your Load Balancer] 

              Example: 

 

gcloud compute url-maps edit http-lb

 

  Step 3: Press ito insert additional pathrule

  Step 4: Add the new pathrule:

             Example: 

 

name: path-matcher-2
  pathRules:
  - paths:
    - /love-to-fetch/*
    - /never-fetch/*
    - /love-to-fly/*

 

Step 5: Press esc, then ctrl + : and type wq! to save and quit. Press Enter.

References: 

url-maps list,

url-maps edit

I hope the above information is helpful.

ah okay... thank you! this is great!

and i could escape by pressing the following keys in quick succession: Esc, :, w, q, !