Add roles and role bindings for events

This commit is contained in:
Mukundan Sundararajan 2020-08-17 16:09:30 -07:00
parent 04b1fdfa57
commit e8299c39f7
5 changed files with 147 additions and 0 deletions

View File

@ -282,5 +282,8 @@ Output should be
kubectl delete ns kube-events
```
## Step 3 - Running in kubernetes cluster
## Next steps
- Explore additional [samples](../README.md#Samples-in-this-repository) and deploy them locally or on Kubernetes.

View File

@ -0,0 +1,12 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: kube-events
namespace: kube-events
spec:
type: bindings.kubernetes
metadata:
- name: namespace
value: kube-events
- name: resyncPreiodInSec
value: "5"

View File

@ -0,0 +1,74 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: kube-events
name: events-reader
rules:
- apiGroups: [""] # "" indicates the core API group
resources: ["events"]
verbs: ["get", "watch", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
# This role binding allows "jane" to read pods in the "default" namespace.
# You need to already have a Role named "pod-reader" in that namespace.
kind: RoleBinding
metadata:
name: read-events
namespace: kube-events
subjects:
# You can specify more than one "subject"
- kind: ServiceAccount
name: default
namespace: kube-events
roleRef:
# "roleRef" specifies the binding to a Role / ClusterRole
kind: Role #this must be Role or ClusterRole
name: events-reader # this must match the name of the Role or ClusterRole you wish to bind to
apiGroup: ""
---
kind: Service
apiVersion: v1
metadata:
name: events-nodeapp
namespace: kube-events
labels:
app: node
spec:
selector:
app: node
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: events-nodeapp
namespace: kube-events
labels:
app: node
spec:
replicas: 1
selector:
matchLabels:
app: node
template:
metadata:
labels:
app: node
annotations:
dapr.io/enabled: "true"
dapr.io/app-id: "events-nodeapp"
dapr.io/app-port: "3000"
spec:
containers:
- name: node
image: dapriosamples/k8s-events-node:edge
ports:
- containerPort: 3000
imagePullPolicy: Always

View File

@ -0,0 +1,52 @@
DOCKER_IMAGE_PREFIX ?=k8s-events-
APPS ?=node
SAMPLE_REGISTRY ?=docker.io/dapriosamples
REL_VERSION ?=edge
# Add latest tag if LATEST_RELEASE is true
LATEST_RELEASE ?=
# Docker image build and push setting
DOCKER:=docker
DOCKERFILE:=Dockerfile
.PHONY: build
SAMPLE_APPS:=$(foreach ITEM,$(APPS),$(DOCKER_IMAGE_PREFIX)$(ITEM))
build: $(SAMPLE_APPS)
# Generate docker image build targets
# Params:
# $(1): app name
# $(2): tag name
define genDockerImageBuild
.PHONY: $(DOCKER_IMAGE_PREFIX)$(1)
$(DOCKER_IMAGE_PREFIX)$(1):
$(DOCKER) build -f $(1)/$(DOCKERFILE) $(1)/. -t $(SAMPLE_REGISTRY)/$(DOCKER_IMAGE_PREFIX)$(1):$(2)
endef
# Generate docker image build targets
$(foreach ITEM,$(APPS),$(eval $(call genDockerImageBuild,$(ITEM),$(REL_VERSION))))
# push docker image to the registry
.PHONY: push
PUSH_SAMPLE_APPS:=$(foreach ITEM,$(APPS),push-$(DOCKER_IMAGE_PREFIX)$(ITEM))
push: $(PUSH_SAMPLE_APPS)
# Generate docker image push targets
# Params:
# $(1): app name
# $(2): tag name
define genDockerImagePush
.PHONY: push-$(DOCKER_IMAGE_PREFIX)$(1)
push-$(DOCKER_IMAGE_PREFIX)$(1):
$(DOCKER) push $(SAMPLE_REGISTRY)/$(DOCKER_IMAGE_PREFIX)$(1):$(2)
ifeq ($(LATEST_RELEASE),true)
$(DOCKER) tag $(SAMPLE_REGISTRY)/$(DOCKER_IMAGE_PREFIX)$(1):$(2) $(SAMPLE_REGISTRY)/$(DOCKER_IMAGE_PREFIX)$(1):latest
$(DOCKER) push $(SAMPLE_REGISTRY)/$(DOCKER_IMAGE_PREFIX)$(1):latest
endif
endef
# Generate docker image push targets
$(foreach ITEM,$(APPS),$(eval $(call genDockerImagePush,$(ITEM),$(REL_VERSION))))

View File

@ -0,0 +1,6 @@
FROM node:8-alpine
WORKDIR /app
COPY . .
RUN npm install
EXPOSE 3000
CMD [ "node", "app.js" ]