Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .infrastructure/app/cluster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4

# Patch the generated kubeadm config with some extra settings
kubeadmConfigPatches:
- |
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
evictionHard:
nodefs.available: "0%"

# Patch it further using a JSON 6902 patch
kubeadmConfigPatchesJSON6902:
- group: kubeadm.k8s.io
version: v1beta3
kind: ClusterConfiguration
patch: |
- op: add
path: /apiServer/certSANs/-
value: my-hostname

# 2 control plane nodes and 2 workers
nodes:
# The control plane node config
- role: control-plane
extraMounts:
- hostPath: /tmp
containerPath: /data
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 30007
hostPort: 30007
- containerPort: 30008
hostPort: 30008
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP

# The worker nodes
- role: worker
extraMounts:
- hostPath: /tmp
containerPath: /data
- role: worker
extraMounts:
- hostPath: /tmp
containerPath: /data
142 changes: 71 additions & 71 deletions .infrastructure/app/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,78 +17,78 @@ spec:
labels:
app: todoapp
spec:
serviceAccountName: secrets-reader
serviceAccountName: todoapp-sa
containers:
- name: todoapp
image: ikulyk404/todoapp:4.0.1
volumeMounts:
- name: todoapp
image: ikulyk404/todoapp:4.0.1
volumeMounts:
- name: data
mountPath: /app/data
- name: app-secrets-volume
mountPath: "/app/secrets"
readOnly: true
- name: app-config-volume
mountPath: "/app/configs"
readOnly: true
resources:
requests:
memory: "256Mi"
cpu: "150m"
limits:
memory: "256Mi"
cpu: "150m"
env:
- name: PYTHONUNBUFFERED
valueFrom:
configMapKeyRef:
name: app-config
key: PYTHONUNBUFFERED
- name: SECRET_KEY
valueFrom:
secretKeyRef:
name: app-secret
key: SECRET_KEY
- name: DB_NAME
valueFrom:
secretKeyRef:
name: app-secret
key: DB_NAME
- name: DB_USER
valueFrom:
secretKeyRef:
name: app-secret
key: DB_USER
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: app-secret
key: DB_PASSWORD
- name: DB_HOST
valueFrom:
secretKeyRef:
name: app-secret
key: DB_HOST
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: api/health
port: 8080
initialDelaySeconds: 60
periodSeconds: 5
readinessProbe:
httpGet:
path: api/ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
volumes:
- name: data
mountPath: /app/data
persistentVolumeClaim:
claimName: pvc-data
- name: app-secrets-volume
mountPath: "/app/secrets"
readOnly: true
secret:
secretName: app-secret
- name: app-config-volume
mountPath: "/app/configs"
readOnly: true
resources:
requests:
memory: "256Mi"
cpu: "150m"
limits:
memory: "256Mi"
cpu: "150m"
env:
- name: PYTHONUNBUFFERED
valueFrom:
configMapKeyRef:
name: app-config
key: PYTHONUNBUFFERED
- name: SECRET_KEY
valueFrom:
secretKeyRef:
name: app-secret
key: SECRET_KEY
- name: DB_NAME
valueFrom:
secretKeyRef:
name: app-secret
key: DB_NAME
- name: DB_USER
valueFrom:
secretKeyRef:
name: app-secret
key: DB_USER
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: app-secret
key: DB_PASSWORD
- name: DB_HOST
valueFrom:
secretKeyRef:
name: app-secret
key: DB_HOST
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: api/health
port: 8080
initialDelaySeconds: 60
periodSeconds: 5
readinessProbe:
httpGet:
path: api/ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
volumes:
- name: data
persistentVolumeClaim:
claimName: pvc-data
- name: app-secrets-volume
secret:
secretName: app-secret
- name: app-config-volume
configMap:
name: app-config
configMap:
name: app-config
31 changes: 31 additions & 0 deletions .infrastructure/security/rbac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: todoapp-sa
namespace: todoapp

---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: todoapp-sr
namespace: todoapp
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list"]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: todoapp-rb
namespace: todoapp
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: todoapp-sr
subjects:
- kind: ServiceAccount
name: todoapp-sa
namespace: todoapp
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,17 @@ Now you can browse the [API](http://localhost:8000/api/) or start on the [landin
1. Make a screenshot of the output and attach it to the PR
1. `README.md` should have instructuions on how to validate the changes
1. Create PR with your changes and attach it for validation on a platform.

run : `kind create cluster --config .infrastructure/app/cluster.yml`
wait
run `sh bootstrap.sh`
wait and pray that you have enough ram

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

run `kubectl get pods -n todoapp`
run `kubectl exec -it <name of the pod you would like to curl from> -n todoapp`
paste inside the pod shell `APISERVER=https://kubernetes.default.svc
SERVICEAC# COUNT=/var/run/secrets/kubernetes.io/serviceaccount
TOKEN=$(cat ${SERVICEACCOUNT}/token)
CACERT=${SE# # RVICEACCOUNT}/ca.crt `
run `curl -s --cacert ${CACERT} --header "Authorization: Bearer $TOKEN" -X GET ${APISERVER}/api/v1/namespaces/todoapp/secrets`

you should get a list of secrets in response
Binary file added Screenshot 2024-08-06 180246.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ kubectl apply -f .infrastructure/app/configMap.yml
kubectl apply -f .infrastructure/app/clusterIp.yml
kubectl apply -f .infrastructure/app/nodeport.yml
kubectl apply -f .infrastructure/app/hpa.yml
kubectl apply -f .infrastructure/security/rbac.yml
kubectl apply -f .infrastructure/app/deployment.yml

# Install Ingress Controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
# kubectl apply -f .infrastructure/ingress/ingress.yml
kubectl apply -f .infrastructure/ingress/ingress.yml