# Service

Service can help task to perform their work. For example a database for your application or an api to your integration test run.

Services can be defined to run in a container or forwarded from a kubernetes cluster. Each need of a task will be available in the container network by the name of the service.

Local tasks can also use needs, but hammerkit will not provide a dns resolution.

## Container

Similar to [container tasks](/hammerkit/task/container.md) need container services an image to run. Tasks can declare the need for services and before the task gets executed, hammerkit will ensure the service is running.

[Healthchecks](/hammerkit/service/container.md#healthcheck) can be used, to ensure that the service is running and ready to be used.

```yaml
services:
  postgres:
    image: postgres
    envs:
      POSTGRES_USER: api
      POSTGRES_DB: api
      POSTGRES_PASSWORD: 123456
    healthcheck:
      cmd: "pg_isready -U postgres"
    ports:
      - 5432

tasks:
  api:
    image: node:alpine
    needs: [postgres]
    cmds:
      - node index.js
```

## Kubernetes

[Kubernetes services](/hammerkit/task/needs.md) allow to use resources from local and remote kubernetes clusters. This allows easy integration with development or staging environments resources and can be used to debug/troubleshoot your application with data from other environments.

```yaml
services:
  postgres-staging:
    context: staging
    ports:
      - 5432:5432
    selector:
      type: deployment
      name: postgres

tasks:
  api-staging:
    image: node:alpine
    needs: [postgres-staging]
    cmds:
      - node index.js
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://no0dles.gitbook.io/hammerkit/service.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
