Skip to content

Commit

Permalink
add hello-kubernetes multi-app run k8s template
Browse files Browse the repository at this point in the history
Signed-off-by: Mukundan Sundararajan <[email protected]>
  • Loading branch information
mukundansundar committed Sep 22, 2023
1 parent e278ba4 commit 3f8c923
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/env/global.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DAPR_CLI_VERSION: 1.11.0
DAPR_RUNTIME_VERSION: 1.11.0
DAPR_CLI_VERSION: 1.12.0-rc.1
DAPR_RUNTIME_VERSION: 1.12.0-rc.3
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v${DAPR_CLI_VERSION}/install/
DAPR_DEFAULT_IMAGE_REGISTRY: ghcr
MACOS_PYTHON_VERSION: 3.10
12 changes: 6 additions & 6 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ jobs:
KIND_VERSION: v0.12.0
KIND_IMAGE_SHA: sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6
strategy:
matrix:
matrix:
os: [ubuntu-latest]
fail-fast: false
steps:
- name: Check out code
- name: Check out code
uses: actions/checkout@v2
- name: Load environment variables
uses: artursouza/export-env-action@v2
Expand Down Expand Up @@ -90,12 +90,12 @@ jobs:
- role: worker
image: kindest/node:${{ env.KUBERNETES_VERSION }}@${{ env.KIND_IMAGE_SHA }}
EOF
# Log the generated kind.yaml for easy reference.
cat kind.yaml
- name: Create KinD Cluster - Linux
if: matrix.os == 'ubuntu-latest'
if: matrix.os == 'ubuntu-latest'
uses: helm/[email protected]
with:
config: kind.yaml
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
run: wget -q ${{ env.DAPR_INSTALL_URL }}/install.sh -O - | /bin/bash -s ${{ env.DAPR_CLI_VERSION }}
- name: Set up Dapr CLI - Windows
if: matrix.os == 'windows-latest'
run: powershell -Command "\$$script=iwr -useb ${{ env.DAPR_INSTALL_URL }}/install.ps1; \$$block=[ScriptBlock]::Create(\$$script); invoke-command -ScriptBlock \$$block -ArgumentList ${{ env.DAPR_CLI_VERSION }}"
run: powershell -Command "\$$script=iwr -useb ${{ env.DAPR_INSTALL_URL }}/install.ps1; \$$block=[ScriptBlock]::Create(\$$script); invoke-command -ScriptBlock \$$block -ArgumentList ${{ env.DAPR_CLI_VERSION }}"
- name: Install Dapr
run: |
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
Expand All @@ -135,7 +135,7 @@ jobs:
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm install redis bitnami/redis
dapr init -k --runtime-version=${{ env.DAPR_RUNTIME_VERSION }} --wait || kubectl get pods --all-namespaces
dapr init -k --dev --runtime-version=${{ env.DAPR_RUNTIME_VERSION }} --wait || kubectl get pods --all-namespaces
kubectl get nodes -o wide
for pod in `dapr status -k | awk '/dapr/ {print $1}'`; do kubectl describe pod -l app=$pod -n dapr-system ; kubectl logs -l app=$pod -n dapr-system; done
- name: Install utilities dependencies
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ packages

# macOS
.DS_Store

# Auto generated deploy dir inside .dapr directory
**/.dapr/deploy
# Auto generated logs dir inside .dapr directory
**/.dapr/logs
98 changes: 89 additions & 9 deletions tutorials/hello-kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ cd quickstarts/tutorials/hello-kubernetes

> **Note**: See https://github.com/dapr/quickstarts#supported-dapr-runtime-version for supported tags. Use `git clone https://github.com/dapr/quickstarts.git` when using the edge version of dapr runtime.
## Step 1 - Setup Dapr on your Kubernetes cluster
## Using the `kubectl` CLI
### Step 1 - Setup Dapr on your Kubernetes cluster

The first thing you need is an RBAC enabled Kubernetes cluster. This could be running on your machine using Minikube, or it could be a fully-fledged cluster in Azure using [AKS](https://azure.microsoft.com/en-us/services/kubernetes-service/).

Expand Down Expand Up @@ -66,7 +67,7 @@ You will see output like the following. All services should show `True` in the H
dapr-sidecar-injector dapr-system True Running 1 1.0.1 13s 2021-03-08 11:00.21
```

## Step 2 - Create and configure a state store
### Step 2 - Create and configure a state store

Dapr can use a number of different state stores (Redis, CosmosDB, DynamoDB, Cassandra, etc) to persist and retrieve state. This demo will use Redis.

Expand All @@ -92,7 +93,7 @@ kubectl apply -f ./deploy/redis.yaml
component.dapr.io/statestore created
```

## Step 3 - Deploy the Node.js app with the Dapr sidecar
### Step 3 - Deploy the Node.js app with the Dapr sidecar

<!-- STEP
name: Deploy Node App
Expand Down Expand Up @@ -149,7 +150,7 @@ This will make your service available on http://localhost:8080.
kubectl get svc nodeapp
```

## Step 4 - Verify Service
### Step 4 - Verify Service

To call the service that you set up port forwarding to, from a command prompt run:

Expand Down Expand Up @@ -214,7 +215,7 @@ Expected output:
dapr dashboard -k -p 9999
```

## Step 5 - Deploy the Python app with the Dapr sidecar
### Step 5 - Deploy the Python app with the Dapr sidecar

Next, take a quick look at the Python app. Navigate to the Python app in the kubernetes quickstart: `cd quickstarts/tutorials/hello-kubernetes/python` and open `app.py`.

Expand Down Expand Up @@ -256,7 +257,7 @@ kubectl rollout status deploy/pythonapp

<!-- END_STEP -->

## Step 6 - Observe messages
### Step 6 - Observe messages

Now that the Node.js and Python applications are deployed, watch messages come through:

Expand Down Expand Up @@ -291,7 +292,7 @@ Got a new order! Order ID: 3
Successfully persisted state for Order ID: 3
```

## Step 7 - Observe API call logs
### Step 7 - Observe API call logs

Now that the Node.js and Python applications are deployed, watch API call logs come through:

Expand Down Expand Up @@ -338,7 +339,7 @@ time="2022-04-27T02:47:49.972688145Z" level=info method="POST /neworder" app_id=
time="2022-04-27T02:47:50.984994545Z" level=info method="POST /neworder" app_id=pythonapp instance=pythonapp-545df48d55-jvj52 scope=dapr.runtime.http-info type=log ver=1.7.2
```

## Step 8 - Confirm successful persistence
### Step 8 - Confirm successful persistence

Call the Node.js app's order endpoint to get the latest order. Grab the external IP address that you saved before and, append "/order" and perform a GET request against it (enter it into your browser, use Postman, or curl it!):

Expand All @@ -349,7 +350,7 @@ curl $NODE_APP/order

You should see the latest JSON in response!

## Step 9 - Cleanup
### Step 9 - Cleanup

Once you're done, you can spin down your Kubernetes resources by navigating to the `./deploy` directory and running:

Expand All @@ -374,6 +375,85 @@ kubectl delete -f .

This will spin down each resource defined by the .yaml files in the `deploy` directory, including the state component.

## Using Dapr Mutli-app run

### Step 1 - Setup Dapr dev mode on your Kubernetes cluster

Follow the steps below to deploy Dapr to it. For more details, see [Deploy Dapr on a Kubernetes cluster](https://docs.dapr.io/operations/hosting/kubernetes/kubernetes-deploy/).

> Please note, any previous Dapr installations in the Kubernetes cluster need to be uninstalled first.
> Please note, the CLI will install to the dapr-system namespace by default. If this namespace does not exist, the CLI will create it.
> If you need to deploy to a different namespace, you can use `-n mynamespace`.
> Please note, the CLI will install `dapr-dev-redis` and `dapr-dev-zipkin` in the `default` namespace.
> Please note, the `statestore`, `pubsub` and `appconfig` default components and configuration will be applied in the `default` Kubernetes namespace only if they do not exist.
```bash
dapr init -k --dev
```

Expected output
```
⌛ Making the jump to hyperspace...
ℹ️ Note: To install Dapr using Helm, see here: https://docs.dapr.io/getting-started/install-dapr-kubernetes/#install-with-helm-advanced
ℹ️ Container images will be pulled from Docker Hub
✅ Deploying the Dapr control plane with latest version to your cluster...
✅ Deploying the Dapr dashboard with latest version to your cluster...
✅ Deploying the Dapr Redis with latest version to your cluster...
✅ Deploying the Dapr Zipkin with latest version to your cluster...
ℹ️ Applying "statestore" component to Kubernetes "default" namespace.
ℹ️ Applying "pubsub" component to Kubernetes "default" namespace.
ℹ️ Applying "appconfig" zipkin configuration to Kubernetes "default" namespace.
✅ Success! Dapr has been installed to namespace dapr-system. To verify, run `dapr status -k' in your terminal. To get started, go here: https://aka.ms/dapr-getting-started
```
### Step 2 - Run the Multi-app run template to deploy both the Node.js and Python apps

To run both the Node.js and Python apps, run the following command from the `hello-kubernetes` directory:
<!-- STEP
name: "Run hello-kubernetes multi-app run tempalte"
sleep: 15
timeout_seconds: 60
expected_stdout_lines:
- 'Deploying app "nodeapp" to Kubernetes'
- 'Deploying app "pythonapp" to Kubernetes'
- '== APP - nodeapp == Node App listening on port 3000!'
- '== APP - nodeapp == Got a new order! Order ID: 4'
- '== APP - nodeapp == Successfully persisted state for Order ID: 4'
expected_stderr_lines:
output_match_mode: substring
match_order: none
-->
```bash
dapr run -k -f dapr.yaml
```
<!-- END_STEP -->

Expected output
```
ℹ️ This is a preview feature and subject to change in future releases.
ℹ️ Validating config and starting app "nodeapp"
ℹ️ Deploying app "nodeapp" to Kubernetes
ℹ️ Deploying service YAML "/path/quickstarts/tutorials/hello-kubernetes/node/.dapr/deploy/service.yaml" to Kubernetes
ℹ️ Deploying deployment YAML "/path/quickstarts/tutorials/hello-kubernetes/node/.dapr/deploy/deployment.yaml" to Kubernetes
ℹ️ Streaming logs for containers in pod "nodeapp-6dcddb44f5-q5gnr"
ℹ️ Writing log files to directory : /path/quickstarts/tutorials/hello-kubernetes/node/.dapr/logs
ℹ️ Validating config and starting app "pythonapp"
ℹ️ Deploying app "pythonapp" to Kubernetes
ℹ️ Deploying deployment YAML "/path/quickstarts/tutorials/hello-kubernetes/python/.dapr/deploy/deployment.yaml" to Kubernetes
== APP - nodeapp == Node App listening on port 3000!
ℹ️ Streaming logs for containers in pod "pythonapp-7479cdcb7b-z827w"
ℹ️ Writing log files to directory : /path/quickstarts/tutorials/hello-kubernetes/python/.dapr/logs
ℹ️ Starting to monitor Kubernetes pods for deletion.
== APP - nodeapp == Got a new order! Order ID: 2
== APP - nodeapp == Successfully persisted state for Order ID: 2
== APP - nodeapp == Got a new order! Order ID: 3
== APP - nodeapp == Successfully persisted state for Order ID: 3
== APP - nodeapp == Got a new order! Order ID: 4
== APP - nodeapp == Successfully persisted state for Order ID: 4
== APP - nodeapp == Got a new order! Order ID: 5
== APP - nodeapp == Successfully persisted state for Order ID: 5
```

## Deploying your code

Now that you're successfully working with Dapr, you probably want to update the code to fit your scenario. The Node.js and Python apps that make up this quickstart are deployed from container images hosted on a private [Azure Container Registry](https://azure.microsoft.com/en-us/services/container-registry/). To create new images with updated code, you'll first need to install docker on your machine. Next, follow these steps:
Expand Down
10 changes: 10 additions & 0 deletions tutorials/hello-kubernetes/dapr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 1
apps:
- appDirPath: ./node
appID: nodeapp
appPort: 3000
containerImage: ghcr.io/dapr/samples/hello-k8s-node:latest
createService: true
- appDirPath: ./python
appID: pythonapp
containerImage: ghcr.io/dapr/samples/hello-k8s-python:latest

0 comments on commit 3f8c923

Please sign in to comment.