forked from inno-devops-labs/S24-core-course-labs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from kolayne-IU-assignments/lab12
Lab12
- Loading branch information
Showing
19 changed files
with
227 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,6 @@ | |
go.work | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/go | ||
|
||
|
||
/persistent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,3 +174,6 @@ poetry.toml | |
pyrightconfig.json | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/python | ||
|
||
|
||
/persistent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import fcntl | ||
from functools import wraps | ||
from threading import Lock | ||
from typing import Callable | ||
|
||
|
||
def increment(filename: str) -> None: | ||
with open(filename, 'rb+') as f: | ||
try: | ||
fcntl.flock(f.fileno(), fcntl.LOCK_EX) | ||
cur = int.from_bytes(f.read(), byteorder='little') | ||
f.seek(0) | ||
cur += 1 | ||
f.write(cur.to_bytes(byteorder='little', length=(cur.bit_length() // 8 + 1))) | ||
f.truncate() # Not necessary, as larger numbers take more bytes | ||
finally: | ||
# Note: will be unlocked anyway when the file is closed | ||
fcntl.flock(f.fileno(), fcntl.LOCK_UN) | ||
|
||
|
||
def increment_on_call(filename: str) -> Callable[[Callable, ...], Callable]: | ||
def decorator(func: Callable) -> Callable: | ||
@wraps(func) | ||
def with_increment(*args, **kwargs): | ||
increment(filename) | ||
return func(*args, **kwargs) | ||
return with_increment | ||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Lab 12 | ||
|
||
## ConfigMap file | ||
|
||
```sh | ||
$ helm install app-py . -f secrets://./env-secrets.yaml | ||
NAME: app-py | ||
LAST DEPLOYED: Mon Apr 22 16:55:16 2024 | ||
NAMESPACE: default | ||
STATUS: deployed | ||
REVISION: 1 | ||
NOTES: | ||
1. Get the application URL by running these commands: | ||
NOTE: It may take a few minutes for the LoadBalancer IP to be available. | ||
You can watch the status of by running 'kubectl get --namespace default svc -w app-py' | ||
export SERVICE_IP=$(kubectl get svc --namespace default app-py --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}") | ||
echo http://$SERVICE_IP:5000 | ||
$ kubectl wait deployment/app-py --for condition=available | ||
deployment.apps/app-py condition met | ||
$ kubectl get po | ||
NAME READY STATUS RESTARTS AGE | ||
app-py-7d7d86657c-df667 1/1 Running 0 30s | ||
app-py-7d7d86657c-hq8nw 1/1 Running 0 30s | ||
app-py-7d7d86657c-jxgrj 1/1 Running 0 30s | ||
app-py-7d7d86657c-twd5l 1/1 Running 0 30s | ||
$ kubectl exec app-py-7d7d86657c-twd5l -- cat /persistent/config.json | ||
{"mole": ["hamsters"], "hamster": ["moles"]} | ||
$ | ||
``` | ||
|
||
## ConfigMap env | ||
|
||
```sh | ||
$ helm install app-go . | ||
NAME: app-go | ||
LAST DEPLOYED: Mon Apr 22 19:26:23 2024 | ||
NAMESPACE: default | ||
STATUS: deployed | ||
REVISION: 1 | ||
NOTES: | ||
1. Get the application URL by running these commands: | ||
NOTE: It may take a few minutes for the LoadBalancer IP to be available. | ||
You can watch the status of by running 'kubectl get --namespace default svc -w app-go-app-py' | ||
export SERVICE_IP=$(kubectl get svc --namespace default app-go-app-py --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}") | ||
echo http://$SERVICE_IP:5000 | ||
$ kubectl get po | ||
NAME READY STATUS RESTARTS AGE | ||
app-go-app-py-59f4c5c69d-8fljp 1/1 Running 0 22s | ||
app-go-app-py-59f4c5c69d-bv496 1/1 Running 0 22s | ||
app-go-app-py-59f4c5c69d-jlz6q 1/1 Running 0 22s | ||
app-go-app-py-59f4c5c69d-t2nnn 1/1 Running 0 22s | ||
$ kubectl debug --image=gcc -it app-go-app-py-59f4c5c69d-8fljp --target=app-py | ||
Targeting container "app-py". If you don't see processes from this container it may be because the container runtime doesn't support this feature. | ||
Defaulting debug container name to debugger-864lv. | ||
If you don't see a command prompt, try pressing enter. | ||
root@app-go-app-py-59f4c5c69d-8fljp:/# echo 'main(){setreuid(geteuid(),geteuid());execl("/bin/sh","sh",0);}' > a.c | ||
root@app-go-app-py-59f4c5c69d-8fljp:/# gcc -o a a.c | ||
a.c:1:1: warning: return type defaults to 'int' [-Wimplicit-int] | ||
1 | main(){setreuid(geteuid(),geteuid());execl("/bin/sh","sh",0);} | ||
| ^~~~ | ||
a.c: In function 'main': | ||
a.c:1:8: warning: implicit declaration of function 'setreuid' [-Wimplicit-function-declaration] | ||
1 | main(){setreuid(geteuid(),geteuid());execl("/bin/sh","sh",0);} | ||
| ^~~~~~~~ | ||
a.c:1:17: warning: implicit declaration of function 'geteuid' [-Wimplicit-function-declaration] | ||
1 | main(){setreuid(geteuid(),geteuid());execl("/bin/sh","sh",0);} | ||
| ^~~~~~~ | ||
a.c:1:38: warning: implicit declaration of function 'execl' [-Wimplicit-function-declaration] | ||
1 | main(){setreuid(geteuid(),geteuid());execl("/bin/sh","sh",0);} | ||
| ^~~~~ | ||
a.c:1:38: warning: incompatible implicit declaration of built-in function 'execl' [-Wbuiltin-declaration-mismatch] | ||
root@app-go-app-py-59f4c5c69d-8fljp:/# chown 2004:2004 a | ||
root@app-go-app-py-59f4c5c69d-8fljp:/# chmod u+s a | ||
root@app-go-app-py-59f4c5c69d-8fljp:/# exec ./a | ||
$ cat /proc/1/environ | sed 's/\x0/\n/g' | grep seal | ||
seal=2001 | ||
monk_seal=century | ||
$ exit | ||
Session ended, the ephemeral container will not be restarted but may be reattached using 'kubectl attach app-go-app-py-59f4c5c69d-8fljp -c debugger-864lv -i -t' if it is still running | ||
$ | ||
``` |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
seal: "2001" | ||
monk_seal: "century" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apiVersion: "v1" | ||
kind: ConfigMap | ||
metadata: | ||
name: {{.Release.Name}}-config-map | ||
data: | ||
{{ .Files.Get "files/config.yaml" | indent 2 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"mole": ["hamsters"], "hamster": ["moles"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ .Release.Name }}-config-map | ||
data: | ||
config.json: {{ .Files.Get "files/config.json" | quote }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.