> ## Documentation Index
> Fetch the complete documentation index at: https://docs.restate.dev/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.restate.dev/feedback

```json
{
  "path": "/guides/connecting-k8s-services-to-cloud",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# Connecting Kubernetes Services to Restate Cloud

> Learn how to connect services on Kubernetes to Restate Cloud.

This guide walks you through connecting Kubernetes services to Restate Cloud with Restate Operator.

We will use [kind](https://kind.sigs.k8s.io/) to create a local Kubernetes cluster for testing purposes.

<Steps>
  <Step title="Prerequisites">
    Install the following on your local machine:

    * [Docker](https://docs.docker.com/)
    * [Helm](https://helm.sh/docs/intro/install/)
    * [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl)
    * [Restate](/installation)
    * [Restate Cloud account](https://cloud.restate.dev/) (free tier available)
    * [kind](https://kind.sigs.k8s.io/docs/user/quick-start)

    This guide was written with kind v0.30.0, [Restate Operator](https://github.com/restatedev/restate-operator/tree/main) v1.8.1, and Restate v1.5.0.
    Contact us on [Discord](https://discord.restate.dev) or [Slack](https://slack.restate.dev) if something does not work as expected.
  </Step>

  <Step title="Create a Restate Cloud environment">
    Open the [Restate Cloud UI](https://cloud.restate.dev) and create a new environment.

    Note the environment id (`env_...`) and request signing key (under security -> HTTP services: `publickeyv1_...`), as you will need them later.
  </Step>

  <Step title="Create a kind cluster">
    ```bash theme={null}
    kind create cluster
    ```

    Set `kubectl` context to `kind-kind`:

    ```bash theme={null}
    kubectl cluster-info --context kind-kind
    ```
  </Step>

  <Step title="Install the Restate Operator">
    Install the Restate Operator via Helm:

    ```bash theme={null}
    helm install restate-operator \
      oci://ghcr.io/restatedev/restate-operator-helm \
      --namespace restate-operator \
      --create-namespace
    ```

    To install the operator, you need to be able to create namespaces and CRDs.
  </Step>

  <Step title="Create a Restate Cloud environment secret">
    Create an API key via `Developers` tab of the Restate Cloud UI and give it `Full` permissions.

    The API key starts with `api_`. Put it in a file named `token` and add the secret:

    ```bash theme={null}
    kubectl create secret generic my-cloud-environment-secret \
    --from-file=token=./token -n restate-operator
    ```
  </Step>

  <Step title="Set up a secure tunnel between the kind cluster and Restate Cloud">
    Create a `RestateCloudEnvironment` manifest in a file called `restate-cloud-env.yaml`:

    ```yaml restate-cloud-env.yaml theme={null}
    apiVersion: restate.dev/v1beta1
    kind: RestateCloudEnvironment
    metadata:
      name: my-cloud-environment
    spec:
      environmentId: env_...
      signingPublicKey: publickeyv1_...
      region: eu
      authentication:
        secret:
          name: my-cloud-environment-secret
          key: token
    ```

    * The `environmentId` can be found in the Restate Cloud UI in the top left corner when you select your environment.
      This ID starts with `env_`.

    * The `signingPublicKey` can be found in the Restate Cloud UI under `Developers`. Scroll down to the `Security` section to find the public key under `HTTP endpoints`.
      The public key starts with `publickeyv1_`.

    * Set the `region` field to the region your Restate Cloud environment is hosted in. Possible values are `us` and `eu`.
      You can find the region next to your environment ID in the Restate Cloud UI.

    Finally, apply the manifest:

    ```bash theme={null}
    kubectl apply -f restate-cloud-env.yaml
    ```

    This deploys a tunnel service in the `restate-operator` namespace that connects the kind cluster to your Restate Cloud environment.

    And wait until the tunnel is ready:

    ```bash theme={null}
    kubectl get pods -w -n restate-operator
    ```
  </Step>

  <Step title="Build and upload a Restate service Docker image to the kind cluster">
    For example, download the TypeScript Hello World service:

    ```bash theme={null}
    restate example typescript-hello-world &&
    cd typescript-hello-world &&
    npm install
    ```

    Build a Docker image for the service:

    ```bash theme={null}
    docker build -t my-restate-service:0.0.1 .
    ```

    Upload the image to the kind cluster:

    ```bash theme={null}
    kind load docker-image my-restate-service:0.0.1
    ```
  </Step>

  <Step title="Deploy the Restate service">
    Create a `RestateDeployment` manifest for the service in a file called `service-deployment.yaml`:

    ```yaml service-deployment.yaml theme={null}
    apiVersion: restate.dev/v1beta1
    kind: RestateDeployment
    metadata:
      name: my-app
    spec:
      replicas: 1
      restate:
        register:
          cloud: my-cloud-environment
      selector:
        matchLabels:
          app: my-app
      template:
        metadata:
          labels:
            app: my-app
        spec:
          containers:
          - name: app
            image: my-restate-service:0.0.1
            ports:
            - name: restate
              containerPort: 9080
    ```

    Apply the manifest to deploy the service:

    ```bash theme={null}
    kubectl apply -f service-deployment.yaml -n restate-test
    ```

    You should now see the deployed service listed in the Restate Cloud UI:

    <Frame>
      <img src={"/img/guides/connecting-k8s-services-to-cloud/registration.png"} />
    </Frame>

    The Restate Operator automatically [registered](/services/versioning#registering-a-deployment) the service with the Restate cluster.
  </Step>

  <Step title="Invoke the service">
    In the Restate Cloud UI playground, you can now invoke the service. In the overview page, click on the `greet` handler of your service to open the playground.
    Then send a request:

    <Frame>
      <img src={"/img/guides/restate-on-kind-with-operator/invoke.png"} />
    </Frame>
  </Step>

  <Step title="🎉 You did it!">
    You have successfully connected a Restate service to Restate Cloud!

    Check out the [Restate Cloud docs](/cloud/connecting-services) for further information.
  </Step>
</Steps>

After you are done experimenting, you can delete the kind cluster:

```bash theme={null}
kind delete cluster
```
