Skip to content

Commit

Permalink
ingres and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
banderlog committed Dec 31, 2021
1 parent fbe21aa commit 138b605
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 44 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,34 @@ Powered with cutting edge *Foretold Termination™* technology (saves time on co

## Installation and usage

**Installation example with kind:**
**kind cluster [with ingress preparation](https://kind.sigs.k8s.io/docs/user/ingress/#using-ingress):**
```
# cluster creation with `kind`
kind create cluster --config=./kind.yaml
# ingress NGINX controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
# wait until is ready to process requests running
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=90s
```

**k8-calc installation:**
```
# installation
helm install k8-calc k8-calc/
# verification -- should output "69"
curl http://localhost:30000/
curl localhost/k8_calc
```

**For different calculation *simply* do:**
+ run `kubectl edit configmap calculateme-configmap`
+ change `calculateme: 60+9` line, save and exit text editor
+ check `http://localhost:30000/`
+ check `localhost/k8_calc`

**To remove everything:**
+ run `kind delete cluster`
Expand Down
3 changes: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [x] Ingres
- [ ] Argo CI/CD
- [ ] Terraform configs for AWS/GCP/Azure
1 change: 1 addition & 0 deletions k8-calc/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: v2
name: k8_calc
description: https://github.com/banderlog/k8s_calc
Expand Down
33 changes: 17 additions & 16 deletions k8-calc/templates/bc-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -17,20 +18,20 @@ spec:
app: bc
spec:
containers:
- name: bc
image: busybox
env:
- name: INPUT
valueFrom:
configMapKeyRef:
name: calculateme-configmap
key: calculateme
command: ['sh']
args: ["-c", "echo ${INPUT} | bc -l > '/tmp/index.html'"]
volumeMounts:
- mountPath: /tmp
name: exch-vol
- name: bc
image: busybox
env:
- name: INPUT
valueFrom:
configMapKeyRef:
name: calculateme-configmap
key: calculateme
command: ['sh']
args: ["-c", "echo ${INPUT} | bc -l > '/tmp/index.html'"]
volumeMounts:
- mountPath: /tmp
name: exch-vol
volumes:
- name: exch-vol
persistentVolumeClaim:
claimName: exch-vol
- name: exch-vol
persistentVolumeClaim:
claimName: exch-vol
1 change: 1 addition & 0 deletions k8-calc/templates/calc-vars.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
Expand Down
3 changes: 2 additions & 1 deletion k8-calc/templates/exch-vol-persistentvolumeclaim.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
Expand All @@ -7,7 +8,7 @@ metadata:
name: exch-vol
spec:
accessModes:
- ReadWriteOnce
- ReadWriteOnce
resources:
requests:
storage: 1Mi
26 changes: 13 additions & 13 deletions k8-calc/templates/http-output-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -15,26 +16,25 @@ spec:
app: output
spec:
containers:
- name: output
image: nginx
volumeMounts:
- mountPath: /usr/share/nginx/html/
name: exch-vol
- name: output
image: nginx
volumeMounts:
- mountPath: /usr/share/nginx/html/
name: exch-vol
volumes:
- name: exch-vol
persistentVolumeClaim:
claimName: exch-vol
- name: exch-vol
persistentVolumeClaim:
claimName: exch-vol
---
apiVersion: v1
kind: Service
metadata:
name: output-service
spec:
type: NodePort
selector:
app: output
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 32000
# Default port used by the image (for Pod)
- targetPort: 80
# port on the Service
port: 5678
19 changes: 19 additions & 0 deletions k8-calc/templates/ingres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
# overcome the exposed URL in the backend service
nginx.ingress.kubernetes.io/rewrite-target: "/"
spec:
rules:
- http:
paths:
- pathType: Prefix
path: "/k8_calc"
backend:
service:
name: output-service
port:
number: 5678
28 changes: 17 additions & 11 deletions kind.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# for proper NodePort mapping
# kind create cluster --config=./kind.yaml
# https://stackoverflow.com/questions/62432961/how-to-use-nodeport-with-kind
apiVersion: kind.x-k8s.io/v1alpha4
# from https://kind.sigs.k8s.io/docs/user/ingress/
---
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 32000
hostPort: 30000
listenAddress: "0.0.0.0" # Optional, defaults to "0.0.0.0"
protocol: tcp # Optional, defaults to tcp
- role: worker
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP

0 comments on commit 138b605

Please sign in to comment.