diff --git a/README.md b/README.md index 7833b30..13f6fa5 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..7d2d8bc --- /dev/null +++ b/TODO.md @@ -0,0 +1,3 @@ +- [x] Ingres +- [ ] Argo CI/CD +- [ ] Terraform configs for AWS/GCP/Azure diff --git a/k8-calc/Chart.yaml b/k8-calc/Chart.yaml index ee54930..a9e5306 100644 --- a/k8-calc/Chart.yaml +++ b/k8-calc/Chart.yaml @@ -1,3 +1,4 @@ +--- apiVersion: v2 name: k8_calc description: https://github.com/banderlog/k8s_calc diff --git a/k8-calc/templates/bc-deployment.yaml b/k8-calc/templates/bc-deployment.yaml index 927491f..4e6ae76 100644 --- a/k8-calc/templates/bc-deployment.yaml +++ b/k8-calc/templates/bc-deployment.yaml @@ -1,3 +1,4 @@ +--- apiVersion: apps/v1 kind: Deployment metadata: @@ -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 diff --git a/k8-calc/templates/calc-vars.yaml b/k8-calc/templates/calc-vars.yaml index e3d5e8c..85ebcc2 100644 --- a/k8-calc/templates/calc-vars.yaml +++ b/k8-calc/templates/calc-vars.yaml @@ -1,3 +1,4 @@ +--- apiVersion: v1 kind: ConfigMap metadata: diff --git a/k8-calc/templates/exch-vol-persistentvolumeclaim.yaml b/k8-calc/templates/exch-vol-persistentvolumeclaim.yaml index 5de2b14..a1b10c8 100644 --- a/k8-calc/templates/exch-vol-persistentvolumeclaim.yaml +++ b/k8-calc/templates/exch-vol-persistentvolumeclaim.yaml @@ -1,3 +1,4 @@ +--- apiVersion: v1 kind: PersistentVolumeClaim metadata: @@ -7,7 +8,7 @@ metadata: name: exch-vol spec: accessModes: - - ReadWriteOnce + - ReadWriteOnce resources: requests: storage: 1Mi diff --git a/k8-calc/templates/http-output-deployment.yaml b/k8-calc/templates/http-output-deployment.yaml index ceda65b..53d5a07 100644 --- a/k8-calc/templates/http-output-deployment.yaml +++ b/k8-calc/templates/http-output-deployment.yaml @@ -1,3 +1,4 @@ +--- apiVersion: apps/v1 kind: Deployment metadata: @@ -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 diff --git a/k8-calc/templates/ingres.yaml b/k8-calc/templates/ingres.yaml new file mode 100644 index 0000000..56e759e --- /dev/null +++ b/k8-calc/templates/ingres.yaml @@ -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 diff --git a/kind.yaml b/kind.yaml index 5c7c972..b7f700f 100644 --- a/kind.yaml +++ b/kind.yaml @@ -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