Class Service
Service acts as a top-level container that manages a set of Routes and Configurations which implement a network service. Service exists to provide a singular abstraction which can be access controlled, reasoned about, and which encapsulates software lifecycle decisions such as rollout policy and team resource ownership. Service acts only as an orchestrator of the underlying Routes and Configurations (much as a kubernetes Deployment orchestrates ReplicaSets).
The Service's controller will track the statuses of its owned Configuration and Route, reflecting their statuses and conditions as its own.
See also: https://github.com/knative/serving/blob/master/docs/spec/overview.md#service
To get more information about Service, see:
- API documentation
- How-to Guides
- Official Documentation
Example Usage
Cloud Run Service Basic
using Pulumi;
using Gcp = Pulumi.Gcp;
class MyStack : Stack
{
public MyStack()
{
var @default = new Gcp.CloudRun.Service("default", new Gcp.CloudRun.ServiceArgs
{
Location = "us-central1",
Template = new Gcp.CloudRun.Inputs.ServiceTemplateArgs
{
Spec = new Gcp.CloudRun.Inputs.ServiceTemplateSpecArgs
{
Containers =
{
new Gcp.CloudRun.Inputs.ServiceTemplateSpecContainerArgs
{
Image = "gcr.io/cloudrun/hello",
},
},
},
},
Traffics =
{
new Gcp.CloudRun.Inputs.ServiceTrafficArgs
{
LatestRevision = true,
Percent = 100,
},
},
});
}
}
Cloud Run Service Sql
using Pulumi;
using Gcp = Pulumi.Gcp;
class MyStack : Stack
{
public MyStack()
{
var instance = new Gcp.Sql.DatabaseInstance("instance", new Gcp.Sql.DatabaseInstanceArgs
{
Region = "us-east1",
Settings = new Gcp.Sql.Inputs.DatabaseInstanceSettingsArgs
{
Tier = "db-f1-micro",
},
});
var @default = new Gcp.CloudRun.Service("default", new Gcp.CloudRun.ServiceArgs
{
AutogenerateRevisionName = true,
Location = "us-central1",
Template = new Gcp.CloudRun.Inputs.ServiceTemplateArgs
{
Metadata = new Gcp.CloudRun.Inputs.ServiceTemplateMetadataArgs
{
Annotations =
{
{ "autoscaling.knative.dev/maxScale", "1000" },
{ "run.googleapis.com/client-name", "demo" },
{ "run.googleapis.com/cloudsql-instances", instance.Name.Apply(name => $"my-project-name:us-central1:{name}") },
},
},
Spec = new Gcp.CloudRun.Inputs.ServiceTemplateSpecArgs
{
Containers =
{
new Gcp.CloudRun.Inputs.ServiceTemplateSpecContainerArgs
{
Image = "gcr.io/cloudrun/hello",
},
},
},
},
});
}
}
Cloud Run Service Multiple Environment Variables
using Pulumi;
using Gcp = Pulumi.Gcp;
class MyStack : Stack
{
public MyStack()
{
var @default = new Gcp.CloudRun.Service("default", new Gcp.CloudRun.ServiceArgs
{
AutogenerateRevisionName = true,
Location = "us-central1",
Template = new Gcp.CloudRun.Inputs.ServiceTemplateArgs
{
Spec = new Gcp.CloudRun.Inputs.ServiceTemplateSpecArgs
{
Containers =
{
new Gcp.CloudRun.Inputs.ServiceTemplateSpecContainerArgs
{
Env =
{
{
{ "name", "SOURCE" },
{ "value", "remote" },
},
{
{ "name", "TARGET" },
{ "value", "home" },
},
},
Image = "gcr.io/cloudrun/hello",
},
},
},
},
Traffics =
{
new Gcp.CloudRun.Inputs.ServiceTrafficArgs
{
LatestRevision = true,
Percent = 100,
},
},
});
}
}
Example Usage - Cloud Run Service Traffic Split
using Pulumi;
using Gcp = Pulumi.Gcp;
class MyStack : Stack
{
public MyStack()
{
var @default = new Gcp.CloudRun.Service("default", new Gcp.CloudRun.ServiceArgs
{
Location = "us-central1",
Template = new Gcp.CloudRun.Inputs.ServiceTemplateArgs
{
Metadata = new Gcp.CloudRun.Inputs.ServiceTemplateMetadataArgs
{
Name = "cloudrun-srv-green",
},
Spec = new Gcp.CloudRun.Inputs.ServiceTemplateSpecArgs
{
Containers =
{
new Gcp.CloudRun.Inputs.ServiceTemplateSpecContainerArgs
{
Image = "gcr.io/cloudrun/hello",
},
},
},
},
Traffics =
{
new Gcp.CloudRun.Inputs.ServiceTrafficArgs
{
Percent = 25,
RevisionName = "cloudrun-srv-green",
},
new Gcp.CloudRun.Inputs.ServiceTrafficArgs
{
Percent = 75,
RevisionName = "cloudrun-srv-blue",
},
},
});
}
}
Inherited Members
Namespace: Pulumi.Gcp.CloudRun
Assembly: Pulumi.Gcp.dll
Syntax
public class Service : CustomResource
Constructors
View SourceService(String, ServiceArgs, CustomResourceOptions)
Create a Service resource with the given unique name, arguments, and options.
Declaration
public Service(string name, ServiceArgs args, CustomResourceOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | The unique name of the resource |
| ServiceArgs | args | The arguments used to populate this resource's properties |
| CustomResourceOptions | options | A bag of options that control this resource's behavior |
Properties
View SourceAutogenerateRevisionName
If set to true, the revision name (template.metadata.name) will be omitted and
autogenerated by Cloud Run. This cannot be set to true while template.metadata.name
is also set.
(For legacy support, if template.metadata.name is unset in state while
this field is set to false, the revision name will still autogenerate.)
Declaration
public Output<bool?> AutogenerateRevisionName { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.Nullable<System.Boolean>> |
Location
The location of the cloud run instance. eg us-central1
Declaration
public Output<string> Location { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
Metadata
Metadata associated with this Service, including name, namespace, labels, and annotations. Structure is documented below.
Declaration
public Output<ServiceMetadata> Metadata { get; }
Property Value
| Type | Description |
|---|---|
| Output<ServiceMetadata> |
Name
Name of the environment variable.
Declaration
public Output<string> Name { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
Project
The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
Declaration
public Output<string> Project { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.String> |
Status
The current status of the Service.
Declaration
public Output<ServiceStatus> Status { get; }
Property Value
| Type | Description |
|---|---|
| Output<ServiceStatus> |
Template
template holds the latest specification for the Revision to be stamped out. The template references the container image, and may also include labels and annotations that should be attached to the Revision. To correlate a Revision, and/or to force a Revision to be created when the spec doesn't otherwise change, a nonce label may be provided in the template metadata. For more details, see: https://github.com/knative/serving/blob/master/docs/client-conventions.md#associate-modifications-with-revisions Cloud Run does not currently support referencing a build that is responsible for materializing the container image from source. Structure is documented below.
Declaration
public Output<ServiceTemplate> Template { get; }
Property Value
| Type | Description |
|---|---|
| Output<ServiceTemplate> |
Traffics
Traffic specifies how to distribute traffic over a collection of Knative Revisions and Configurations Structure is documented below.
Declaration
public Output<ImmutableArray<ServiceTraffic>> Traffics { get; }
Property Value
| Type | Description |
|---|---|
| Output<System.Collections.Immutable.ImmutableArray<ServiceTraffic>> |
Methods
View SourceGet(String, Input<String>, ServiceState, CustomResourceOptions)
Get an existing Service resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
Declaration
public static Service Get(string name, Input<string> id, ServiceState state = null, CustomResourceOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | The unique name of the resulting resource. |
| Input<System.String> | id | The unique provider ID of the resource to lookup. |
| ServiceState | state | Any extra arguments used during the lookup. |
| CustomResourceOptions | options | A bag of options that control this resource's behavior |
Returns
| Type | Description |
|---|---|
| Service |