LogoLogo
Bonsai (0.13) DocsGitHubDiscord CommunityGarden Enterprise
Acorn (0.12)
Acorn (0.12)
  • Welcome!
  • 🌳Basics
    • How Garden Works
    • Quickstart Guide
    • The Stack Graph (Terminology)
  • 🌻Tutorials
    • Your First Project
      • 1. Initialize a Project
      • 2. Connect to a Cluster
      • 3. Deploy and Test
      • 4. Configure Your Project
  • 💐Using Garden
    • Configuration Overview
    • Projects
    • Modules
    • Services
    • Tests
    • Tasks
    • Workflows
    • Variables and templating
    • Module Templates
    • Using the CLI
  • 🌿Kubernetes Plugins
    • About
    • Remote K8s Plugin Configuration
      • 1. Create a Cluster
        • AWS
        • GCP
        • Azure
      • 2. Configure Container Registry (Optional)
        • AWS
        • GCP
        • Azure
      • 3. Set Up Ingress, TLS and DNS
      • 4. Configure the Provider
    • Local K8s Plugin Configuration
      • 1. Install Local Kubernetes
      • 2. Configure the Provider
    • Module Configuration
      • Container
      • Kubernetes
      • Helm
      • PersistentVolumeClaim
      • ConfigMap
    • Advanced
      • In-Cluster Building
      • Minimal RBAC Configuration for Development Clusters
      • Deploying to Production
  • 🌺Terraform Plugin
    • About
    • Provider Configuration
    • Module Configuration
  • ☘️Pulumi Plugin
    • About
    • Provider Configuration
    • Module Configuration
  • 🌹Other Plugins
    • Container
    • Exec (local scripts)
  • 🌼Guides
    • Installing Garden
    • Adopting Garden
    • Code Synchronization (Dev Mode)
    • Connecting a local service to a K8s cluster (Local Mode)
    • Environments and namespaces
    • Hot Reload
    • Migrating from Docker Compose to Garden
    • Using Garden in CI
  • 🌷Advanced
    • cert-manager Integration
    • Using Remote Sources
    • Custom Commands
  • 🪷Reference
    • Providers
      • conftest-container
      • conftest-kubernetes
      • conftest
      • container
      • exec
      • hadolint
      • jib
      • kubernetes
      • local-kubernetes
      • maven-container
      • octant
      • openfaas
      • pulumi
      • terraform
    • Module Types
      • configmap
      • conftest
      • container
      • exec
      • hadolint
      • helm
      • jib-container
      • kubernetes
      • maven-container
      • openfaas
      • persistentvolumeclaim
      • pulumi
      • templated
      • terraform
    • Template Strings
      • Project configuration context
      • Environment configuration context
      • Provider configuration context
      • Module configuration context
      • Remote Source configuration context
      • Project Output configuration context
      • Custom Command configuration context
      • Workflow configuration context
      • Template Helper Functions
    • Glossary
    • Commands
    • Project Configuration
    • Module Template Configuration
    • Workflow Configuration
  • 🎋Misc
    • FAQ
    • Troubleshooting
    • Telemetry
Powered by GitBook
On this page
  • How it Works
  • Calling Services
  • Services in the Stack Graph
  • Examples
  • Simple Container Service
  • Frontend Service
  • Advanced
  • Disabling Services
  • How Services Map to Kubernetes Resources
  • Further Reading
  • Next Steps

Was this helpful?

  1. Using Garden

Services

PreviousModulesNextTests

Last updated 1 year ago

Was this helpful?

Services are the basic unit of deployment in Garden. You add them when you want to run your code somewhere. A simple service configuration looks like this:

kind: Module
type: container
services:
  - name: backend
    ports:
      - name: http
        containerPort: 8080

Note that not all have services.

How it Works

Services belong to modules and you'll usually have a single service per module. You can think of a service as a running instance of your module.

You deploy your services with the garden deploy command. You can also delete services with the garden delete service command. And you can get service logs with the garden logs command.

Calling Services

The following is specific to the Kubernetes providers.

If you specify a port for a given service, other services from inside the cluster can reach it. By default, it's reachable from http://my-service:<port>/.

If you specify an ingress, your can reach your service from outside the cluster. For example by using the garden call command or with curl.

The default ingress for local development is http://demo-project.local.demo.garden/<ingress-name>. You can override this by setting a hostname under the ingress directive.

Services in the Stack Graph

Services correspond to a deploy action in the Stack Graph.

  • Services implicitly depend on the build step of their parent module.

  • Services can depend on tasks and other services.

  • Tasks and tests can depend on services.

Examples

Here are some simple examples of services in Garden. Note that these are specific to Kubernetes.

Simple Container Service

This example shows a backend service with a health check. Notice that it doesn't have an ingress since it's not meant to be reachable from the outside.

Notice also that the servicePort is set to 80, the default port. This is so that we can call the service directly from within the cluster with http://backend/my-endpoint.

The containerPort (the port that the process inside the container is listening on) is set to 8080.

Finally, we set an environment variable that's available to the service at runtime, and can be referenced in our code.

kind: Module
type: container
services:
  - name: backend
    ports:
      - name: http
        containerPort: 8080
        servicePort: 80
    healthCheck:
      httpGet:
        path: /healthz
        port: http
  - env:
      # You can access this variable at runtime in your code.
      DATABASE_URL: https://my-database:5432/

Frontend Service

This example shows a frontend service. It has an ingress so that it's reachable from outside the cluster. We've also set a custom hostname so that the full path becomes: http://my-app.my-org/.

This service has a dependency on a backend service which means it won't be deployed until the backend service has been deployed and is responding to health checks. This also means that the service gets re-deployed on changes to the backend.

kind: Module
type: container
services:
  - name: frontend
    ports:
      - name: http
        containerPort: 8080
    ingresses:
      - path: /
        port: http
        hostname: my-app.my-org
    dependencies:
      - backend

Advanced

Disabling Services

Module types that allow you to configure services generally also allow you to disable services by setting disabled: true in the service configuration. You can also disable them conditionally using template strings. For example, to disable a container module service for a specific environment, you could do something like this:

kind: Module
type: container
...
services:
  - name: frontend
    disabled: ${environment.name == "prod"}
    ...

Services are also implicitly disabled when the parent module is disabled.

How Services Map to Kubernetes Resources

By default the Kubernetes provider does a rolling update for deployments.

Further Reading

Next Steps

A container service maps to a Kubernetes . If you specify a port, Garden will create a for the Deployment. And if you specify an ingress, Garden will create a corresponding Kubernetes .

For full service configuration by module type, please take a look at our .

In the , we'll see how Garden can run your tests for you.

💐
modules types
Deployment resource
Service resource
Ingress resource
reference docs
next section