This is just an example of setting up a Go service on a kubernetes with DAPR. The service is using a dapr redis state component to save data. The deployment environment is kubernetes that comes with Docker desktop for windows. The Go code is very simplistic as I am just starting to play with Go.
- Install dapr to k8s with helm as shown at this page
- Deploy redis to k8s with helm
- Instructions is at this page
- Add dapr state component
- Build docker image of your app/api
- Deploy your api on k8s (with dapr annotation for your pod)
- Test your app/api
- Deploy a dapr component to use the above redis as a store (using deploy/redis.yaml)
- This yaml is compatible with above redis deployment
kubectl apply -f deploy/redis.yaml
- Build an image of your program,
docker build -t project-service .
- Deploy your program (deployment, service, ingress) to k8s
kubectl apply -f deploy/project-service.yaml
- Test your api at 'alpaca.example.com/project-service'
This is the uri you set up with your Ingress in file deploy/project-service.yaml
- Just hello world and extra url params
curl http://alpaca.example.com/project-service curl http://alpaca.example.com/project-service/query?name=Fred&age=93
- Post a project json to the api. It will return the object saved.
curl -X POST -H "Content-Type: application/json" -d @project.json http://alpaca.example.com/project-service
kubectl get pods
ingress-nginx-controller-57cb5bf694-2n68f 1/1 Running 3 39h
project-service-78f99c65f6-qq94c 2/2 Running 0 79m
redis-master-0 1/1 Running 6 2d16h
redis-replicas-0 1/1 Running 7 2d16h
redis-replicas-1 1/1 Running 6 2d16h
redis-replicas-2 1/1 Running 6 2d16h
k exec -it redis-master-0 -- redis-cli
auth <password>
keys *
hgetall <key>