Skip to content

Commit

Permalink
add: k8s support
Browse files Browse the repository at this point in the history
  • Loading branch information
crossphoton authored Dec 16, 2021
1 parent 9194a08 commit ed94625
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
# Dependency directories (remove the comment below to include it)
# vendor/

*.pb.go
app.env
examples/
examples/
manifest/*
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ FROM golang:1.14.6-alpine3.12 as builder

COPY . /app/
WORKDIR /app
RUN sh ./gen_proto.sh
RUN go mod download

RUN CGO_ENABLED=0 GOOS=linux go build -o ./ -a -installsuffix cgo /app/...
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,20 @@ Templated are parsed using `html/template` package.
### Docker
```
docker run -d --name email-microservice --env-file app.env -p 5555:5555 crossphoton/email-microservice
docker run -d --name email-microservice --env-file app.env -p 5555:5555 crossphoton/email-microservice:v1.0.0
```

### Kubernetes

> TODO
Use the [deployment.yml](manifest/deployment.yml) file for the service deployment.

This requires a `smtp-secret` secret to be created which contains the following:
- `SMTP_HOST` - SMTP host
- `SMTP_PORT` - SMTP port
- `SMTP_EMAIL` - SMTP email
- `SMTP_PASSWORD` - SMTP password

A template of this is also provided (See [secrets.yml](manifest/secrets.yml))

### Locally
1. Clone the repository
Expand All @@ -101,6 +109,7 @@ Generate the client code using the proto file [email.proto](./email.proto)
## TODO
- Tracing
- Graceful shutdown
- Switch to Uber Go Style. [See the guide here](https://github.com/uber-go/guide/blob/master/style.md).
-

## License
Expand Down
60 changes: 60 additions & 0 deletions manifest/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: email-service
spec:
selector:
matchLabels:
app: email-service
template:
metadata:
labels:
app: email-service
spec:
containers:
- name: server
image: crossphoton/email-microservice:v1.0.0
resources:
limits:
memory: "128Mi"
cpu: "250m"
env:
- name: PORT
value: "5555"
- name: PROMETHEUS_PORT
value: "9090"
- name: ENVIRONMENT
value: "production"
# - name: DISABLE_EMAIL
# value: "true"

envFrom:
- secretRef:
name: smtp-secret
readinessProbe:
periodSeconds: 5
exec:
command: ["/bin/grpc_health_probe", "-addr=:5555"]
livenessProbe:
periodSeconds: 5
exec:
command: ["/bin/grpc_health_probe", "-addr=:5555"]
ports:
- containerPort: 5555
- containerPort: 9090
---
apiVersion: v1
kind: Service
metadata:
name: email-service
spec:
type: ClusterIP
selector:
app: email-service
ports:
- name: grpc
port: 5555
targetPort: 5555
- name: prometheus
port: 9090
targetPort: 9090
13 changes: 13 additions & 0 deletions manifest/secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Here you should provide the smtp environment variables

apiVersion: v1
kind: Secret
metadata:
name: smtp-secret
namespace: testing
type: Opaque
data:
SMTP_HOST: <SMTP_HOST>
SMTP_PORT: <SMTP_PORT>
SMTP_EMAIL: <SMTP_EMAIL>
SMTP_PASSWORD: <SMTP_PASSWORD>

0 comments on commit ed94625

Please sign in to comment.