【问题标题】:Setting up load balancer frontend with on GCP with Pulumi使用 Pulumi 在 GCP 上设置负载均衡器前端
【发布时间】:2021-05-15 14:50:05
【问题描述】:

现在我正在学习如何使用 Pulumi 设置由 GCP 存储桶提供服务的网站,但是,我坚持在最后一步公开 IP 地址并将其附加到 LB。除了This load balancer has no frontend configured,一切看起来都不错

我认为ForwardingRule 是我所需要的,但除了BucketBackend 之外它没有(见下面的代码和输出)。

对如何前进有什么建议吗?

####### WEBSITE ##########
web_bucket = gcp.storage.Bucket('web',
    project="myproj",
    cors=[gcp.storage.BucketCorArgs(
        max_age_seconds=3600,
        methods=[
            "GET",
        ],
        origins=["https://myproj.com", "https://sandbox.myproj.com"],
        response_headers=["*"],
    )],
    force_destroy=True,
    location="US",
    uniform_bucket_level_access=True,
    website=gcp.storage.BucketWebsiteArgs(
        main_page_suffix="index.html",
        not_found_page="404.html",
    ),
)
pulumi.export('web bucket', web_bucket.url)

ssl_certificate = gcp.compute.SSLCertificate("SSLCertificate",
    project="myproj",
    name_prefix="certificate-",
    private_key=(lambda path: open(path).read())("ssl/private.key"),
    certificate=(lambda path: open(path).read())("ssl/certificate.crt"))

http_health_check = gcp.compute.HttpHealthCheck("httphealthcheck",
    project="myproj",
    request_path="/",
    check_interval_sec=1,
    timeout_sec=1
)

# Backend Bucket Service
web_backend = gcp.compute.BackendBucket("web-backend",
    project="myproj",
    description="Serves website",
    bucket_name=web_bucket.name,
    enable_cdn=True
)

# LB Backend hostpath and rules
url_map = gcp.compute.URLMap("urlmap",
    project="myproj",
    description="URL mapping",
    default_service=web_backend.id,
    host_rules=[gcp.compute.URLMapHostRuleArgs(
        hosts=["myproj.io"],
        path_matcher="allpaths",
    )],
    path_matchers=[gcp.compute.URLMapPathMatcherArgs(
        name="allpaths",
        default_service=web_backend.id,
        path_rules=[gcp.compute.URLMapPathMatcherPathRuleArgs(
            paths=["/*"],
            service=web_backend.id,
        )],
    )]
)

# Route to backed (bucket backend)
target_https_proxy = gcp.compute.TargetHttpsProxy("targethttpsproxy",
    project="myproj",
    url_map=url_map.id,
    ssl_certificates=[ssl_certificate.id])

# Forwarding rule for External Network Load Balancing using Backend Services
web_forward = gcp.compute.ForwardingRule("webforward",
    project="myproj",
    region="us-central1",
    port_range="80",
    backend_service=web_backend.id # this doesn't work
)
Diagnostics:
  gcp:compute:ForwardingRule (default):
    error: 1 error occurred:
        * Error creating ForwardingRule: googleapi: Error 400: Invalid value for field 'resource.backendService': 'https://compute.googleapis.com/compute/beta/projects/myproj/global/backendBuckets/web-backend-576fa1b'. Unexpected resource collection 'backendBuckets'., invalid

【问题讨论】:

    标签: google-cloud-platform load-balancing bucket pulumi


    【解决方案1】:

    我使用了错误的转发规则类。由于LB设置区域转发错误。

    # Forwarding rule for External Network Load Balancing using Backend Services
    web_forward = gcp.compute.GlobalForwardingRule("webforward",
        project="myproj",
        port_range="443",
        target=nbprod_target_https_proxy.self_link
    )
    

    【讨论】:

      猜你喜欢
      • 2020-07-22
      • 2018-02-18
      • 2021-08-31
      • 2020-05-08
      • 2019-08-24
      • 1970-01-01
      • 1970-01-01
      • 2019-11-22
      • 2021-12-07
      相关资源
      最近更新 更多