# Source: https://docs.hypermode.com/dgraph/self-managed/single-server-cluster.md

# Single Server Cluster Setup

<Info>
  We're overhauling Dgraph's docs to make them clearer and more approachable. If
  you notice any issues during this transition or have suggestions, please
  [let us know](https://github.com/hypermodeinc/docs/issues).
</Info>

You can install a single server Dgraph cluster in Kubernetes.

## Before you begin

* Install the
  [Kubernetes command line tool](https://kubernetes.io/docs/tasks/tools/install-kubectl/).
* Ensure that you have a production-ready Kubernetes cluster running in a cloud
  provider of your choice.
* (Optional) To run Dgraph Alpha with TLS, see
  [TLS Configuration](./tls-configuration).

## Installing a single server Dgraph cluster

1. Verify that you are able to access the nodes in the Kubernetes cluster:

   ```sh
   kubectl get nodes
   ```

   An output similar to this appears:

   ```sh
   NAME                                          STATUS   ROLES    AGE   VERSION
   <aws-ip-hostname>.<region>.compute.internal   Ready    <none>   1m   v1.15.11-eks-af3caf
   <aws-ip-hostname>.<region>.compute.internal   Ready    <none>   1m   v1.15.11-eks-af3caf
   ```

   After your Kubernetes cluster is up, you can use
   [dgraph-single.yaml](https://github.com/hypermodeinc/dgraph/blob/master/contrib/config/kubernetes/dgraph-single/dgraph-single.yaml)
   to start a Zero, Alpha, and Ratel UI services.

2. Start a StatefulSet that creates a single Pod with `Zero`, `Alpha`, and
   `Ratel UI`:

   ```sh
   kubectl create --filename https://raw.githubusercontent.com/hypermodeinc/dgraph/master/contrib/config/kubernetes/dgraph-single/dgraph-single.yaml
   ```

   An output similar to this appears:

   ```sh
   service/dgraph-public created
   statefulset.apps/dgraph created
   ```

3. Confirm that the Pod was created successfully.

   ```sh
   kubectl get pods
   ```

   An output similar to this appears:

   ```sh
   NAME       READY     STATUS    RESTARTS   AGE
   dgraph-0   3/3       Running   0          1m
   ```

4. List the containers running in the Pod `dgraph-0`:

   ```sh
   kubectl get pods dgraph-0 -o jsonpath='{range .spec.containers[*]}{.name}{"\n"}{end}'
   ```

   An output similar to this appears:

   ```sh
   ratel
   zero
   alpha
   ```

   You can check the logs for the containers in the pod using
   `kubectl logs --follow dgraph-0 <CONTAINER_NAME>`.

5. Port forward from your local machine to the Pod:

   ```sh
   kubectl port-forward pod/dgraph-0 8080:8080
   kubectl port-forward pod/dgraph-0 8000:8000
   ```

6. Go to `http://localhost:8000` to access Dgraph using the Ratel UI.

## Deleting Dgraph single server resources

Delete all the resources using:

```sh
kubectl delete --filename https://raw.githubusercontent.com/hypermodeinc/dgraph/master/contrib/config/kubernetes/dgraph-single/dgraph-single.yaml
kubectl delete persistentvolumeclaims --selector app=dgraph
```