Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1edc98f

Browse files
committed
Merge branch 'dk/prebuilds-docs' of github.com:/coder/coder into dk/prebuilds-docs
2 parentsad056d7 +e4332d7 commit1edc98f

File tree

1 file changed

+118
-104
lines changed

1 file changed

+118
-104
lines changed
Lines changed: 118 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
#Prebuilt workspaces
22

3-
##Overview
3+
Prebuilt workspaces allow template administrators to improve the developer experience by reducing workspace
4+
creation time with an automatically maintained pool of ready-to-use workspaces for specific parameter presets.
45

5-
Prebuilt workspaces let you pre-provision and maintain a pool of ready-to-use workspaces.
6-
Instead of creating a new workspace when a developer requests one, if a workspace matches a preset defined in the
7-
template parameters, Coder assigns an existing instance, reducing setup time significantly.
6+
The template administrator configures a template to provision prebuilt workspaces in the background, and then when a developer creates
7+
a new workspace that matches the preset, Coder assigns them an existing prebuilt instance.
8+
Prebuilt workspaces significantly reduce wait times, especially for templates with complex provisioning or lengthy startup procedures.
9+
10+
Prebuilt workspaces are:
11+
12+
- Created and maintained automatically by Coder to match your specified preset configurations.
13+
- Claimed transparently when developers create workspaces.
14+
- Monitored and replaced automatically to maintain your desired pool size.
815

916
##Prerequisites
1017

11-
- Premium license
12-
- Use`coder/coder` Terraform provider`>= 2.3.0-pre2` in your template (**TODO: update with latest version**)
13-
- Enable the`workspace-prebuilds`[experiment](../../../reference/cli/server.md#--experiments)
18+
-[**Premium license**](../../licensing/index.md)
19+
-**Compatible Terraform provider**:Use`coder/coder` Terraform provider`>= 2.3.0-pre2`. (**TODO: update with latest version**)
20+
-**Feature flag**:Enable the`workspace-prebuilds`[experiment](../../../reference/cli/server.md#--experiments).
1421

15-
##Configuration
22+
##Enable prebuilt workspaces for template presets
1623

17-
1. In your Terraform template, add a`prebuilds` block within a`coder_workspace_preset` block:
24+
In your template, add a`prebuilds` block within a`coder_workspace_preset` block to identify how many prebuilt
25+
instances your Coder deployment should maintain:
1826

1927
```hcl
2028
data "coder_workspace_preset" "goland" {
@@ -25,120 +33,113 @@ template parameters, Coder assigns an existing instance, reducing setup time sig
2533
memory = 16
2634
}
2735
prebuilds {
28-
instances = 3
36+
instances = 3 # Number of prebuilt workspaces to maintain
2937
}
3038
}
3139
```
3240

33-
1. Publish and import the template.
34-
1. Coder automatically provisions another prebuilt workspace through an internal reconciliation loop
35-
(similar to Kubernetes) to maintain the number of specified`instances`.
41+
After you create or update the template, Coder automatically provisions and maintains prebuilt workspaces through an
42+
internal reconciliation loop (similar to Kubernetes) to maintain the number of specified`instances`.
3643

37-
##Workspace ownership
44+
Prebuilt workspaces are displayed in the list of workspaces on the Coder dashboard with the owner set to`prebuilds`.
3845

39-
After a prebuilt workspace is created, it is owned by the unprivileged pseudo-user`prebuilds`, which belongs to the
40-
`Everyone` group.
41-
Coder uses the`prebuilds` user to identify unclaimed prebuilt workspaces.
42-
You can add the`prebuilds` user to additional groups if you need to.
46+
##Prebuilt workspace lifecycle
4347

44-
##View prebuilt workspaces
48+
Prebuilt workspaces follow a specific lifecycle from creation through eligibility to claiming.
4549

46-
You can view prebuilt workspaces in the**Workspaces** view in theCoder dashboard:
50+
Expand each item in this list for more information about thestage:
4751

48-
![A prebuilt workspace in the dashboard](../../../images/admin/templates/extend-templates/prebuilt/prebuilt-workspaces.png)
52+
1. <details><summary>After you configure a preset with a prebuilt workspace and publish the template, Coder provisions
53+
the prebuilt workspace(s).</summary>
4954

50-
##Claiming
55+
1. Coder automatically creates prebuilt workspaces up to the specified`instances` count.
56+
1. Each new prebuild is initially owned by an unprivileged system pseudo-user named`prebuilds`.
57+
- The`prebuilds` user belongs to the`Everyone` group (you can add it to additional groups if needed).
58+
1. Each prebuilt workspace receives a randomly generated name for identification.
59+
1. The workspace is provisioned like a regular workspace.
5160

52-
A prebuilt workspace is automatically and transparently assigned to a user when a:
61+
</details>
5362

54-
- User creates a new workspace via the API or the Coder web UI.
55-
- User selected a preset which has been configured for prebuilds.
56-
- Prebuilt workspace is in an eligible state.
63+
1. <details><summary>Coder prepares the prebuilt workspace to be claimed by a developer.</summary>
5764

58-
The ownership of theprebuilt workspacewill change to the requesting user, and thisisreferred toas a "claim".
65+
Before aprebuilt workspace isavailable tousers:
5966

60-
##Eligibility
67+
1. The workspace reaches`running` state.
68+
1. The agent connects to coderd.
69+
1. The agent starts its bootstrap procedures and startup scripts complete successfully.
70+
1. The agent reports`ready` status.
6171

62-
When a prebuilt workspace is running, and its agent has completed all of its bootstrap procedures and executed its
63-
startup scripts, the workspace will be marked eligible to be claimed.
72+
Prebuilt workspaces that fail during provisioning are retried with an exponential backoff to prevent transient failures.
6473

65-
##Relationship to workspace presets
74+
</details>
6675

67-
[Workspace presets](./parameters.md#workspace-presets-beta) allow you to configure commonly used combinations of
68-
parameters into a single option, which makes it easier for developers to pick one that fits their needs.
76+
1. <details><summary>When a developer selects requests a new workspace, the claiming process occurs:</summary>
6977

70-
Prebuilt workspaces need to have a preset defined to match the base configuration of a workspace, i.e. the preset
71-
needs to define all the required parameters needed to build a workspace. These parameters are necessary in order to
72-
build workspaces in the background.
78+
1. Developer selects a template and preset that has prebuilt workspaces configured.
79+
1. If an eligible prebuilt workspace exists, it's automatically assigned to the user.
80+
1. Ownership transfers from the`prebuilds` user to the requesting user.
81+
1. The workspace name changes to the user's requested name.
82+
1. The process is transparent to the developer - they simply see a workspace ready faster than normal.
7383

74-
Parameters which are not required or not part of a preset can still be used with prebuilt workspaces.
75-
The preset defines the minimum required set of parameters, and these are immutable.
84+
This ownership transfer happens automatically without any special action required by the user.
7685

77-
##Update a prebuilt workspace
86+
</details>
7887

79-
Prebuiltworkspacesare not automatically updated after they are created.
88+
You can view available prebuiltworkspacesin the**Workspaces** view in the Coder dashboard:
8089

81-
When a template version changes, all prebuilt workspaces relating to an inactive template version are destroyed.
82-
New prebuilt workspaces will be provisioned for the active template version.
83-
84-
You may want to invalidate a prebuilt workspace when your template version does not change but a referenced dependency does,
85-
which is necessary for running an up-to-date workspace. For example, if
86-
an[AMI](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html) which is referenced by your template is updated,
87-
you can simply delete the prebuilt workspaces, and they will be recreated with the latest AMI.
90+
![A prebuilt workspace in the dashboard](../../../images/admin/templates/extend-templates/prebuilt/prebuilt-workspaces.png)
8891

89-
_In future releases, we will allow operators to invalidate theirprebuiltworkspaces programmatically._
92+
###Template updates and theprebuiltworkspace lifecycle
9093

91-
##Quotas
94+
Prebuilt workspaces have specific behavior when templates are updated:
9295

93-
Prebuilt workspaces can be used in conjunction with[Resource Quotas](../../users/quotas.md). Given
94-
that all unclaimed prebuilt workspaces are[owned](#workspace-ownership) by the`prebuilds` user, you may configure a quota for
95-
any group which this user appears in.
96+
1. When a template version changes, prebuilt workspaces for old versions are automatically deleted.
97+
1. New prebuilt workspaces are created for the active template version.
98+
1. Prebuilt workspaces aren't automatically updated after creation.
99+
1. If dependencies change (e.g., an[AMI](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html) update) without a template version change, you can:
100+
- Delete the existing prebuilt workspaces manually.
101+
- Coder will automatically create new prebuilt workspaces with the updated dependencies.
96102

97-
Oncethequota is exceeded, prebuilt workspaceswill fail provisioning like regular workspaces would.
103+
The system always maintainsthedesired number of prebuilt workspacesfor the active template version.
98104

99-
##Current Limitations
105+
###Relationship to workspace presets
100106

101-
- Organizations
107+
Prebuilt workspaces are tightly integrated with[workspace presets](./parameters.md#workspace-presets-beta):
102108

103-
Prebuilt workspaces can only be utilized by the default organization.
109+
1. Each prebuilt workspace is associated with a specific template preset.
110+
1. The preset must define all required parameters needed to build the workspace.
111+
1. The preset parameters define the base configuration and are immutable after they're claimed.
112+
1. Parameters that are not defined in the preset can still be customized by users when they claim a workspace.
104113

105-
[coder/internal#364](https://github.com/coder/internal/issues/364)
114+
##Administration and troubleshooting
106115

107-
- Autoscaling
116+
###Managing resource quotas
108117

109-
Prebuilt workspacesremain running until they are claimed.
110-
We do not currently have an autoscaling mechanism to reducethenumber of instances after working hours.
118+
Prebuilt workspacescan be used in conjunction with[resource quotas](../../users/quotas.md).
119+
Because unclaimed prebuilt workspaces are owned bythe`prebuilds` user, you can:
111120

112-
[coder/internal#312](https://github.com/coder/internal/issues/312)
121+
1. Configure quotas for any group that includes this user.
122+
1. Set appropriate limits to balance prebuilt workspace availability with resource constraints.
113123

114-
##Gotchas
124+
If a quota is exceeded, the prebuilt workspace will fail provisioning the same way other workspaces do.
115125

116-
###Resource Replacement
126+
###Template configuration best practices
117127

118-
When a prebuilt workspace is created, it is initially[owned](#workspace-ownership) by the`prebuilds` user and a random name
119-
is generated for it.
120-
When`terraform apply` runs, it will provide these values during provisioning in the
121-
[`coder_workspace`](https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/workspace) and
122-
[`coder_workspace_owner`](https://registry.terraform.io/providers/coder/coder/latest/docs/data-sources/workspace_owner)
123-
datasources.
128+
####Preventing resource replacement
124129

125-
Once a prebuilt workspace is claimed, the ownership of that workspace changes to the requesting user and
126-
`terraform apply` is run again, now with updated values for the aforementioned datasources.
130+
When a prebuilt workspace is claimed, another`terraform apply` run occurs with new values for the workspace owner and name.
127131

128-
If your template has used these datasources in immutable fields (i.e. the
129-
[`user_data`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#user_data-1) field in
130-
an`aws_instance` resource), Terraform will interpret these changes as_drift_ and will therefore destroy and recreate
131-
the resource.
132+
This can cause issues:
132133

133-
This is obviously undesirable because the prebuilt workspace will now have to provision_again_, while the user waits,
134-
eliminating the value of the prior pre-provisioning.
134+
1. The workspace is initially created with values from the`prebuilds` user and a random name.
135+
1. After claiming, various workspace properties change (ownership, name, and potentially other values), which Terraform sees as configuration drift.
136+
1. If these values are used in immutable fields, Terraform will destroy and recreate the resource, eliminating the benefit of prebuilds.
135137

136-
Should this occur when a prebuilt workspace is claimed, all Template Admins will receive a notification which will
137-
link them to the build logs to investigate which resource was being replaced.
138+
For example, when these values are used in immutable fields like the AWS instance`user_data`, you'll see resource replacement during claiming:
138139

139140
![Resource replacement notification](../../../images/admin/templates/extend-templates/prebuilt/replacement-notification.png)
140141

141-
Toavoid this problem, you will need toadd a`lifecycle` blockto your resource:
142+
Toprevent this,add a`lifecycle` blockwith`ignore_changes`:
142143

143144
```hcl
144145
resource "docker_container" "workspace" {
@@ -152,14 +153,7 @@ resource "docker_container" "workspace" {
152153
}
153154
```
154155

155-
In the above example, the`docker_container` would be created with a`name` attribute which includes references to the
156-
initial owner (i.e.`prebuilds`), and will never change - even when the values of`data.coder_workspace_owner.me.name`
157-
and`data.coder_workspace.me.name` change in the above example.`name` is immutable like`user_data` above.
158-
159-
You can read more about`ignore_changes`in the[Terraform documentation](https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#ignore_changes).
160-
161-
Should certain mutable attributes be required to change, you can use a more targeted approach by providing a list of
162-
attributes to`ignore_changes`:
156+
For more targeted control, specify which attributes to ignore:
163157

164158
```hcl
165159
resource "docker_container" "workspace" {
@@ -173,23 +167,43 @@ resource "docker_container" "workspace" {
173167
}
174168
```
175169

176-
##Troubleshooting
170+
Learn more about`ignore_changes` in the[Terraform documentation](https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#ignore_changes).
171+
172+
###Current limitations
173+
174+
The prebuilt workspaces feature has these current limitations:
175+
176+
-**Organizations**
177+
178+
Prebuilt workspaces can only be used with the default organization.
179+
180+
[coder/internal#364](https://github.com/coder/internal/issues/364)
181+
182+
-**Autoscaling**
183+
184+
Prebuilt workspaces remain running until claimed. There's no automated mechanism to reduce instances during off-hours.
185+
186+
[coder/internal#312](https://github.com/coder/internal/issues/312)
187+
188+
###Monitoring and observability
189+
190+
####Available metrics
191+
192+
Coder provides several metrics to monitor your prebuilt workspaces:
193+
194+
-`coderd_prebuilt_workspaces_created_total` (counter): Total number of prebuilt workspaces created to meet the desired instance count.
195+
-`coderd_prebuilt_workspaces_failed_total` (counter): Total number of prebuilt workspaces that failed to build.
196+
-`coderd_prebuilt_workspaces_claimed_total` (counter): Total number of prebuilt workspaces claimed by users.
197+
-`coderd_prebuilt_workspaces_desired` (gauge): Target number of prebuilt workspaces that should be available.
198+
-`coderd_prebuilt_workspaces_running` (gauge): Current number of prebuilt workspaces in a`running` state.
199+
-`coderd_prebuilt_workspaces_eligible` (gauge): Current number of prebuilt workspaces eligible to be claimed.
177200

178-
###Metrics
201+
####Logs
179202

180-
-`coderd_prebuilt_workspaces_created_total` (counter): Total number of prebuilt workspaces that have been created to
181-
meet the desired instance count of each template preset
182-
-`coderd_prebuilt_workspaces_failed_total` (counter): Total number of prebuilt workspaces that failed to build
183-
-`coderd_prebuilt_workspaces_claimed_total` (counter): Total number of prebuilt workspaces which were claimed by users.
184-
Claiming refers to creating a workspace with a preset selected for which eligible prebuilt workspaces are available
185-
and one is reassigned to a user
186-
-`coderd_prebuilt_workspaces_desired` (gauge): Target number of prebuilt workspaces that should be available for each
187-
template preset
188-
-`coderd_prebuilt_workspaces_running` (gauge): Current number of prebuilt workspaces that are in a running state. These
189-
workspaces have started successfully but may not yet be claimable by users (see`coderd_prebuilt_workspaces_eligible`)
190-
-`coderd_prebuilt_workspaces_eligible` (gauge): Current number of prebuilt workspaces that are eligible to be claimed
191-
by users. These are workspaces that have completed their build process with their agent reporting 'ready' status
203+
Search for`coderd.prebuilds:` in your logs to track the reconciliation loop's behavior.
192204

193-
###Logs
205+
These logs provide information about:
194206

195-
Search for`coderd.prebuilds:` to gain insight into the behavior of the reconciliation loop.
207+
1. Creation and deletion attempts for prebuilt workspaces.
208+
1. Backoff events after failed builds.
209+
1. Claiming operations.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp