Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions examples/kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Running Examples on KinD

Prerequisites:

- kind
- dapr cli
- kubectl

## Setup local registry and kind

```shell
./setup_kind.sh
```

## Run any component on kubernetes

> Note: Some components may require a dependency like redis/kafka and others. So you need to install it first.

```shell
./run.sh state.memory
```

## See it working

Forward local 3500 port to remote daprd port and make requests:

```sh
curl -X POST -H "Content-Type: application/json" -d '[{ "key": "name", "value": "Bruce Wayne", "metadata": { "ttlInSeconds": "60"}}]' http://localhost:3500/v1.0/state/default
```

```sh
curl --silent http://localhost:3500/v1.0/state/default/name |base64 --decode
```
33 changes: 33 additions & 0 deletions examples/kubernetes/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: __COMPONENT__
labels:
app: __COMPONENT__
spec:
replicas: 1
selector:
matchLabels:
app: __COMPONENT__
template:
metadata:
labels:
app: __COMPONENT__
annotations:
dapr.io/unix-domain-socket-path: "/tmp/dapr-components-sockets" ## required, the default path where Dapr uses for registering components.
dapr.io/app-id: "__COMPONENT__"
dapr.io/enabled: "true"
spec:
volumes: ## required, the sockets volume
- name: dapr-unix-domain-socket
emptyDir: {}
containers:
- name: component
image: localhost:5001/__COMPONENT__:latest
imagePullPolicy: Always
volumeMounts: # required, the sockets volume mount
- name: dapr-unix-domain-socket
mountPath: /tmp/dapr-components-sockets
env:
- name: DAPR_COMPONENT_SOCKET_PATH # Tells the component where the sockets should be created.
value: /tmp/dapr-components-sockets/pluggable.sock
9 changes: 9 additions & 0 deletions examples/kubernetes/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

COMPONENT=${1:-state.memory}
COMPONENT_IMAGE=$(echo $COMPONENT |sed -e s/"\."/"-"/gi)
docker build -t $COMPONENT_IMAGE -f ../Dockerfile ../.. --build-arg COMPONENT=$COMPONENT
docker tag $COMPONENT_IMAGE localhost:5001/$COMPONENT_IMAGE:latest
docker push localhost:5001/$COMPONENT_IMAGE:latest
kubectl apply -f ../$COMPONENT/component.yml
cat deployment.yaml | sed s/__COMPONENT__/$COMPONENT_IMAGE/gi | kubectl apply -f -
44 changes: 44 additions & 0 deletions examples/kubernetes/setup_kind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
### Local registry setup
set -o errexit

# create registry container unless it already exists
reg_name='kind-registry'
reg_port='5001'
if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then
docker run \
-d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \
registry:2
fi

# create a cluster with the local registry enabled in containerd
cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"]
endpoint = ["http://${reg_name}:5000"]
EOF

# connect the registry to the cluster network if not already connected
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
docker network connect "kind" "${reg_name}"
fi

# Document the local registry
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: local-registry-hosting
namespace: kube-public
data:
localRegistryHosting.v1: |
host: "localhost:${reg_port}"
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
EOF

dapr init -k --wait

###
1 change: 1 addition & 0 deletions examples/state.memory/component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ spec:
type: state.memory-pluggable
version: v1
initTimeout: 10s
metadata: []
4 changes: 3 additions & 1 deletion socket_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ limitations under the License.

package dapr

import "syscall"
import (
"syscall"
)

func init() {
//nolint
Expand Down