Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tutorial based on hello-kubernetes #52

Merged
merged 14 commits into from
Jul 23, 2024
121 changes: 121 additions & 0 deletions docs/tutorial/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Dapr Shared Getting Started Tutorial

This tutorial follows up on the Dapr Hello Kubernetes tutorial that can be found here in the Dapr Quickstart repo:

https://github.com/dapr/quickstarts/tree/master/tutorials/hello-kubernetes

Instead of deploying Dapr as a sidecar we are going to use Dapr Shared instances.


## Prerequisites and Installation

Before proceeding make sure that you have the necessary tools installed on your system. We will create a local KinD cluster to install Dapr, some applications, and an instance of Dapr Shared.

To get started, make sure you have the following CLIs installed:

- [Docker](https://www.docker.com/)

- [KinD (Kubernetes in Docker)](https://kind.sigs.k8s.io/docs/user/quick-start/)

- [kubectl](https://kubernetes.io/docs/tasks/tools/)

- [Helm](https://helm.sh/docs/intro/install/)


## Creating a local Kubernetes cluster with KinD:

Create a Kubernetes cluster with KinD defaults by running the following command:

```bash
kind create cluster
```

Next install a version of the Dapr control plane into the cluster:

```
helm repo add dapr https://dapr.github.io/helm-charts/
helm repo update
helm upgrade --install dapr dapr/dapr \
--version=1.13.2 \
--namespace dapr-system \
--create-namespace \
--wait
```
Or use the Dapr CLI to install the latest version with the following command

salaboy marked this conversation as resolved.
Show resolved Hide resolved
`dapr init -k`
## Running the Hello Kubernetes example

Next install a Redis instance into the cluster using Helm

```shell
helm install redis oci://registry-1.docker.io/bitnamicharts/redis --version 17.11.3 --set "architecture=standalone" --set "master.persistence.size=1Gi"
```

Once Redis is installed you can deploy our application workloads, including a statestore component by running:

```shell
kubectl apply -f deploy/
```

This creates a statestore component, a Node application and a Python application.

If you inspect the `deploy/node.yaml` and `deploy/python.yaml` files you see that both are define two environment variables:

```yaml
- name: DAPR_HTTP_ENDPOINT
value: http://nodeapp-dapr.default.svc.cluster.local:3500
- name: DAPR_GRPC_ENDPOINT
value: http://nodeapp-dapr.default.svc.cluster.local:50001
```

These two environment variables let the Dapr SDK know where the Dapr endpoints are hosted (usually for the sidecar these are located on `localhost`).

Because these workloads are not annotated with Dapr annotations, the Dapr Control Plane will not inject a Dapr sidecar, instead we will create two instances of the Dapr runtime using Dapr Shared for our services to use.


## Creating two Dapr Shared instances for our services

For each application service that needs to talk to the Dapr APIs we need to deploy a new Dapr Shared instance. Each instance have a one to one relationship with Dapr Application Ids.

Let's create a new Dapr Shared instance for the Node (`nodeapp`) application:

```sh
helm install nodeapp-shared oci://docker.io/daprio/dapr-shared-chart --set shared.appId=nodeapp

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the helm chart here abstracts what is actually happening too much. Can you add a link to the helm chart at least so that users can inspect the values?

```

Notice that the `shared.appId` is the name used for the endpoint variables defined in the previous section.

Let's do the same for the Python application:

```sh
helm install pythonapp-shared oci://docker.io/daprio/dapr-shared-chart --set shared.appId=pythonapp
```

Once both Dapr Shared instances are up, the application can connect to the Dapr APIs on the shared instance for the particular application. You can validate this by interacting with the `nodeapp` by running:

```
kubectl port-forward service/nodeapp 8080:80
```

And then sending a request to place a new order:

```shell
curl --request POST --data "@sample.json" --header Content-Type:application/json http://localhost:8080/neworder
salaboy marked this conversation as resolved.
Show resolved Hide resolved
```

Validate the order has been persisted:

```shell
curl http://localhost:8080/order
```

Expected Output:
```
{ "orderId": "42" }
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really encourage adding a K8s command here illustrate where the dapr instances are running. Given these are Dapr deployments and this is a default 3 node Kind cluster, you can show that these instance may be running on different nodes compared to where the app is running. In other words, how do you teach someone that Dapr Shared is installed correctly, or how do I look at a cluster and see that this has dapr shared running on it compared to having side car deployment?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree here! Daprd is being deployed as a Deployment right? I was unsure if deployment or DS initially.

Maybe just add a screenshot of the Daprd's running on the cluster at least?

## Get involved

If you want to contribute to Dapr Shared, please get in touch, create an issue, or submit a Pull Request.
You can also check the Project Roadmap to see what is coming or to find out how you can help us get the next version done.
45 changes: 45 additions & 0 deletions docs/tutorial/deploy/node.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
kind: Service
apiVersion: v1
metadata:
name: nodeapp
labels:
app: node
spec:
selector:
app: node
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: LoadBalancer

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nodeapp
labels:
app: node
spec:
replicas: 1
selector:
matchLabels:
app: node
template:
metadata:
labels:
app: node
spec:
containers:
- name: node
image: ghcr.io/dapr/samples/hello-k8s-node:latest
env:
- name: APP_PORT
value: "3000"
- name: DAPR_HTTP_ENDPOINT
value: http://nodeapp-dapr.default.svc.cluster.local:3500
- name: DAPR_GRPC_ENDPOINT
value: http://nodeapp-dapr.default.svc.cluster.local:50001
ports:
- containerPort: 3000
imagePullPolicy: Always
24 changes: 24 additions & 0 deletions docs/tutorial/deploy/python.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pythonapp
labels:
app: python
spec:
replicas: 1
selector:
matchLabels:
app: python
template:
metadata:
labels:
app: python
spec:
containers:
- name: python
image: ghcr.io/dapr/samples/hello-k8s-python:latest
env:
- name: DAPR_HTTP_ENDPOINT
value: http://pythonapp-dapr.default.svc.cluster.local:3500
- name: DAPR_GRPC_ENDPOINT
value: http://pythonapp-dapr.default.svc.cluster.local:50001
21 changes: 21 additions & 0 deletions docs/tutorial/deploy/redis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: statestore
spec:
type: state.redis
version: v1
metadata:
# These settings will work out of the box if you use `helm install
# bitnami/redis`. If you have your own setup, replace
# `redis-master:6379` with your own Redis master address, and the
# Redis password with your own Secret's name. For more information,
# see https://docs.dapr.io/operations/components/component-secrets .
- name: redisHost
value: redis-master:6379
- name: redisPassword
secretKeyRef:
name: redis
key: redis-password
auth:
secretStore: kubernetes
5 changes: 5 additions & 0 deletions docs/tutorial/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"data": {
"orderId": "42"
}
}
134 changes: 0 additions & 134 deletions tutorial/README.md

This file was deleted.

Binary file removed tutorial/imgs/pizza-store.png
Binary file not shown.
Loading
Loading