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 #14

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
4 changes: 2 additions & 2 deletions .infrastructure/ingress/ingress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ metadata:
name: todoapp-ingress
namespace: todoapp
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- pathType: Prefix
path: /(|$)(.*)
path: /
backend:
service:
name: todoapp-service
Expand Down
32 changes: 32 additions & 0 deletions .infrastructure/security/rbac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: secrets-reader
namespace: todoapp

---

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

---

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: secrets-reader-binding
namespace: todoapp
subjects:
- kind: ServiceAccount
name: secrets-reader
roleRef:
kind: Role
name: secrets-reader
apiGroup: rbac.authorization.k8s.io
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,70 @@ 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.


---

### Validation

Verify the `Role` is created:

```bash
kubectl get roles -n todoapp
```
Expected output:
```yaml
NAME CREATED AT
secrets-reader 2024-07-11T10:33:47Z
```
Describe the `Role` to ensure it allows listing secrets:

```bash
kubectl describe role secrets-reader -n todoapp
```
Expected output:
```yaml
Name: secrets-reader
Labels: <none>
Annotations: <none>
PolicyRule:
Resources Non-Resource URLs Resource Names Verbs
--------- ----------------- -------------- -----
secrets [] [] [list]
```

Verify the `RoleBinding` is created :

```bash
kubectl get rolebinding -n todoapp
```
Expected output:
```yaml
NAME ROLE AGE
secrets-reader-binding Role/secrets-reader 19m
```
Describe the `RoleBinding` to ensure it properly binds the `Role` to the `ServiceAccount`:
```bash
kubectl describe rolebinding secrets-reader-binding -n todoapp
```
Expected output:
```yaml
Name: secrets-reader-binding
Labels: <none>
Annotations: <none>
Role:
Kind: Role
Name: secrets-reader
Subjects:
Kind Name Namespace
---- ---- ---------
ServiceAccount secrets-reader
```
Check the `ServiceAccount` is used by the `Deployment`:
```bash
kubectl get deployment todoapp -n todoapp -o jsonpath='{.spec.template.spec.serviceAccountName}'
```
Expected output:
```yaml
secrets-reader
```
16 changes: 15 additions & 1 deletion bootstrap.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#!/bin/bash

kind create cluster --config cluster.yml

kubectl apply -f .infrastructure/mysql/ns.yml
kubectl apply -f .infrastructure/mysql/configMap.yml
kubectl apply -f .infrastructure/mysql/secret.yml
kubectl apply -f .infrastructure/mysql/service.yml
kubectl apply -f .infrastructure/mysql/statefulSet.yml

kubectl apply -f .infrastructure/app/ns.yml

kubectl apply -f .infrastructure/security/rbac.yml

kubectl apply -f .infrastructure/app/pv.yml
kubectl apply -f .infrastructure/app/pvc.yml
kubectl apply -f .infrastructure/app/secret.yml
Expand All @@ -15,6 +21,14 @@ kubectl apply -f .infrastructure/app/nodeport.yml
kubectl apply -f .infrastructure/app/hpa.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 wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=600s

kubectl apply -f .infrastructure/ingress/ingress.yml