Skip to content

Commit 58afd60

Browse files
committed
Add deployment examples.
1 parent 067ca1d commit 58afd60

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,21 @@ docker build -t <dockerimage-name> \
77
--build-arg SLACK_WEBHOOK_URL_ARG=${SLACK_WEBHOOK_URL} \
88
--build-arg CLUSTER_NAMESPACE_ARG=${CLUSTER_NAMESPACE}
99
```
10+
11+
After building the image you can run this in your local, however
12+
it's not recommended to include your secret like the webhook into
13+
your `Dockerimage` directly.
14+
15+
## Deployment
16+
17+
- Build
18+
```
19+
docker build -t <dockerimage-name>
20+
```
21+
- Push `Dockerimage`
22+
- Create a `Secret`
23+
```
24+
kubectl -n <NAMESPACE> create secret generic app-secret --from-literal=slackwebhook='<SLACK_WEBHOOK>'
25+
```
26+
- Change the fields of `$namespace`, `$clusterNamespace`, and `$imageName`.
27+
- You can use `kubectl apply -f k8s --recursive`

k8s/deployments.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: kubernetes-batch-api-example
5+
namespace: $namespace
6+
labels:
7+
app: kubernetes-batch-api-example
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: kubernetes-batch-api-example
13+
template:
14+
metadata:
15+
labels:
16+
app: kubernetes-batch-api-example
17+
spec:
18+
containers:
19+
- name: kubernetes-batch-api-example
20+
image: $imageName
21+
envFrom:
22+
- configMapRef:
23+
name: environment-variable
24+
env:
25+
- name: SLACK_WEBHOOK_URL
26+
valueFrom:
27+
secretKeyRef:
28+
name: app-secret
29+
key: slack-webhook

k8s/environment-variable.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: environment-variable
5+
namespace: $namespace
6+
data:
7+
CLUSTER_NAMESPACE: $clusterNamespace

src/api/kubernetes.py

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class Constants:
1313

1414
class KubernetesApi:
1515
def __init__(self):
16+
"""
17+
Note that in cluster you'll use the in cluster config,
18+
meanwhile when you try it on your local, you'll use your own kubeconfig.
19+
"""
1620
try:
1721
config.load_incluster_config()
1822
except:

0 commit comments

Comments
 (0)