diff --git a/core/src/plugins/container/config.ts b/core/src/plugins/container/config.ts index 47cfc184f1..578da5d55e 100644 --- a/core/src/plugins/container/config.ts +++ b/core/src/plugins/container/config.ts @@ -305,6 +305,7 @@ export const containerDevModeSchema = () => export interface ContainerLocalModeSpec { localAppPort: number + enableLivenessProbe: boolean command?: string[] containerName?: string } @@ -318,6 +319,12 @@ export const containerLocalModeSchema = () => .description("The command to run the local application (optional)."), containerName: joi.string().optional().description("The k8s name of the remote container (optional)."), localAppPort: joi.number().description("The working port of the local application."), + enableLivenessProbe: joi + .boolean() + .default(true) + .description( + "Enable liveness probes for the local service (over the proxy container) if true. True by default. Set it to false to disable liveness probes." + ), }).description(dedent` Specifies necessary configuration details of the local application which will replace a target remote service in the k8s cluster. @@ -329,6 +336,9 @@ export const containerLocalModeSchema = () => Local mode is enabled by setting the \`--local-mode\` option on the \`garden deploy\` command. + The liveness probes are enabled by default. + Those can be disabled by setting \`services[].localMode.enableLivenessProbe: false\`. + See the [Local Mode guide](${localModeGuideLink}) for more information. `) diff --git a/core/src/plugins/kubernetes/local-mode.ts b/core/src/plugins/kubernetes/local-mode.ts index 9b373602ce..ff4e671d56 100644 --- a/core/src/plugins/kubernetes/local-mode.ts +++ b/core/src/plugins/kubernetes/local-mode.ts @@ -334,18 +334,20 @@ function patchOriginalServiceSpec( /** * Patches the main container by adding localMode-specific settings like ports, environment variables, - * docker image name and readiness probe settings. + * docker image name and health-check settings. * * @param mainContainer the main container object to be patched * @param proxyContainerName the target container name * @param localModeEnvVars the list of localMode-specific environment variables * @param localModePorts the list of localMode-specific ports (e.g. ssh port for tunnel setup) + * @param localModeSpec the local mode configuration spec */ function patchMainContainer( mainContainer: V1Container, proxyContainerName: string, localModeEnvVars: PrimitiveMap, - localModePorts: ServicePortSpec[] + localModePorts: ServicePortSpec[], + localModeSpec: ContainerLocalModeSpec ) { mainContainer.name = proxyContainerName mainContainer.image = reverseProxyImageName @@ -367,6 +369,10 @@ function patchMainContainer( containerPort: port.containerPort, }) } + + if (!localModeSpec.enableLivenessProbe) { + delete mainContainer.livenessProbe + } } /** @@ -405,7 +411,7 @@ export async function configureLocalMode(configParams: ConfigureLocalModeParams) const localModePorts = prepareLocalModePorts(configParams) patchOriginalServiceSpec(service.spec, localModeEnvVars, localModePorts) - patchMainContainer(mainContainer, proxyContainerName, localModeEnvVars, localModePorts) + patchMainContainer(mainContainer, proxyContainerName, localModeEnvVars, localModePorts, localModeSpec) // todo: check if anything else should be configured here } diff --git a/core/test/integ/src/plugins/kubernetes/container/deployment.ts b/core/test/integ/src/plugins/kubernetes/container/deployment.ts index 05d6beef4f..c233ac164c 100644 --- a/core/test/integ/src/plugins/kubernetes/container/deployment.ts +++ b/core/test/integ/src/plugins/kubernetes/container/deployment.ts @@ -362,6 +362,29 @@ describe("kubernetes container deployment handlers", () => { }) }) + it("should delete liveness probes in local mode when livenessProbeEnabled=false", async () => { + const service = graph.getService("local-mode") + service.spec.localMode.enableLivenessProbe = false + const namespace = provider.config.namespace!.name! + + const resource = await createWorkloadManifest({ + api, + provider, + service, + runtimeContext: emptyRuntimeContext, + namespace, + enableDevMode: false, + enableHotReload: false, + enableLocalMode: true, // <---- + log: garden.log, + production: false, + blueGreen: false, + }) + + const appContainerSpec = resource.spec.template?.spec?.containers.find((c) => c.name === "local-mode") + expect(appContainerSpec!.livenessProbe).to.be.undefined + }) + it("should remove readiness probes when in local mode", async () => { const service = graph.getService("local-mode") const namespace = provider.config.namespace!.name! diff --git a/docs/guides/running-service-in-local-mode.md b/docs/guides/running-service-in-local-mode.md index 4961dee561..566274d9e9 100644 --- a/docs/guides/running-service-in-local-mode.md +++ b/docs/guides/running-service-in-local-mode.md @@ -73,7 +73,17 @@ inspect the `known_hosts` file and clean it up manually. ## Configuration To configure a service for local mode, add `localMode` to your module/service configuration to specify your target -services: +services. + +### Health-checks + +The readiness probes are disabled for all services running in local mode. This has been done because of some technical +reasons. The k8s cluster readiness checks are applied to a proxy container which sends the traffic to the local service. +When a readiness probe happens, the target local service and the relevant port forward are not ready yet. + +The _local mode_ supports liveness probes. The liveness probles have intentionally longer initial delays, just to make +sure that the local services and port forward have enough time to start. The liveness probes are enabled by default, but +can be disabled if necessary. See the example below. ### Configuring local mode for `container` modules @@ -86,6 +96,7 @@ services: args: [ npm, start ] localMode: localAppPort: 8090 # The port of the local service, will be used for port-forward setup + enableLivenessProbe: false # Optional, `true` is the default value. Set it to `false` if you need to disable liveness probes for the local service. command: [ npm, run, serve ] # Starts the local service which will replace the target one in the k8s cluster containerName: "node-service" # Optional. The name of the target k8s service. It will be inferred automatically if this option is not defined. ... diff --git a/docs/reference/module-types/container.md b/docs/reference/module-types/container.md index da65b67cb5..befda1299d 100644 --- a/docs/reference/module-types/container.md +++ b/docs/reference/module-types/container.md @@ -312,6 +312,9 @@ services: # # Local mode is enabled by setting the `--local-mode` option on the `garden deploy` command. # + # The liveness probes are enabled by default. + # Those can be disabled by setting `services[].localMode.enableLivenessProbe: false`. + # # See the [Local Mode guide](https://docs.garden.io/guides/running-service-in-local-mode.md) for more information. localMode: # The command to run the local application (optional). @@ -323,6 +326,10 @@ services: # The working port of the local application. localAppPort: + # Enable liveness probes for the local service (over the proxy container) if true. True by default. Set it to + # false to disable liveness probes. + enableLivenessProbe: true + # List of ingress endpoints that the service exposes. ingresses: - # Annotations to attach to the ingress (Note: May not be applicable to all providers) @@ -1399,6 +1406,9 @@ The `command` should not depend on the current service or module path. Local mode is enabled by setting the `--local-mode` option on the `garden deploy` command. +The liveness probes are enabled by default. +Those can be disabled by setting `services[].localMode.enableLivenessProbe: false`. + See the [Local Mode guide](https://docs.garden.io/guides/running-service-in-local-mode.md) for more information. | Type | Required | @@ -1435,6 +1445,16 @@ The working port of the local application. | -------- | -------- | | `number` | No | +### `services[].localMode.enableLivenessProbe` + +[services](#services) > [localMode](#serviceslocalmode) > enableLivenessProbe + +Enable liveness probes for the local service (over the proxy container) if true. True by default. Set it to false to disable liveness probes. + +| Type | Default | Required | +| --------- | ------- | -------- | +| `boolean` | `true` | No | + ### `services[].ingresses[]` [services](#services) > ingresses diff --git a/docs/reference/module-types/jib-container.md b/docs/reference/module-types/jib-container.md index 575b0c91a2..aff8658509 100644 --- a/docs/reference/module-types/jib-container.md +++ b/docs/reference/module-types/jib-container.md @@ -333,6 +333,9 @@ services: # # Local mode is enabled by setting the `--local-mode` option on the `garden deploy` command. # + # The liveness probes are enabled by default. + # Those can be disabled by setting `services[].localMode.enableLivenessProbe: false`. + # # See the [Local Mode guide](https://docs.garden.io/guides/running-service-in-local-mode.md) for more information. localMode: # The command to run the local application (optional). @@ -344,6 +347,10 @@ services: # The working port of the local application. localAppPort: + # Enable liveness probes for the local service (over the proxy container) if true. True by default. Set it to + # false to disable liveness probes. + enableLivenessProbe: true + # List of ingress endpoints that the service exposes. ingresses: - # Annotations to attach to the ingress (Note: May not be applicable to all providers) @@ -1470,6 +1477,9 @@ The `command` should not depend on the current service or module path. Local mode is enabled by setting the `--local-mode` option on the `garden deploy` command. +The liveness probes are enabled by default. +Those can be disabled by setting `services[].localMode.enableLivenessProbe: false`. + See the [Local Mode guide](https://docs.garden.io/guides/running-service-in-local-mode.md) for more information. | Type | Required | @@ -1506,6 +1516,16 @@ The working port of the local application. | -------- | -------- | | `number` | No | +### `services[].localMode.enableLivenessProbe` + +[services](#services) > [localMode](#serviceslocalmode) > enableLivenessProbe + +Enable liveness probes for the local service (over the proxy container) if true. True by default. Set it to false to disable liveness probes. + +| Type | Default | Required | +| --------- | ------- | -------- | +| `boolean` | `true` | No | + ### `services[].ingresses[]` [services](#services) > ingresses diff --git a/docs/reference/module-types/maven-container.md b/docs/reference/module-types/maven-container.md index bb5e78cded..ee49a68c3c 100644 --- a/docs/reference/module-types/maven-container.md +++ b/docs/reference/module-types/maven-container.md @@ -312,6 +312,9 @@ services: # # Local mode is enabled by setting the `--local-mode` option on the `garden deploy` command. # + # The liveness probes are enabled by default. + # Those can be disabled by setting `services[].localMode.enableLivenessProbe: false`. + # # See the [Local Mode guide](https://docs.garden.io/guides/running-service-in-local-mode.md) for more information. localMode: # The command to run the local application (optional). @@ -323,6 +326,10 @@ services: # The working port of the local application. localAppPort: + # Enable liveness probes for the local service (over the proxy container) if true. True by default. Set it to + # false to disable liveness probes. + enableLivenessProbe: true + # List of ingress endpoints that the service exposes. ingresses: - # Annotations to attach to the ingress (Note: May not be applicable to all providers) @@ -1409,6 +1416,9 @@ The `command` should not depend on the current service or module path. Local mode is enabled by setting the `--local-mode` option on the `garden deploy` command. +The liveness probes are enabled by default. +Those can be disabled by setting `services[].localMode.enableLivenessProbe: false`. + See the [Local Mode guide](https://docs.garden.io/guides/running-service-in-local-mode.md) for more information. | Type | Required | @@ -1445,6 +1455,16 @@ The working port of the local application. | -------- | -------- | | `number` | No | +### `services[].localMode.enableLivenessProbe` + +[services](#services) > [localMode](#serviceslocalmode) > enableLivenessProbe + +Enable liveness probes for the local service (over the proxy container) if true. True by default. Set it to false to disable liveness probes. + +| Type | Default | Required | +| --------- | ------- | -------- | +| `boolean` | `true` | No | + ### `services[].ingresses[]` [services](#services) > ingresses