-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAN-229 Add container about print podname (#113)
- Loading branch information
1 parent
dccf5c1
commit 76dc46e
Showing
9 changed files
with
133 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Ignore Python cache and virtual environment folders | ||
__pycache__/ | ||
*.pyc | ||
*.pyo | ||
venv/ | ||
Makefile | ||
manifests/ | ||
README.md | ||
imgs/ |
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,11 @@ | ||
FROM python:3.12.7-slim | ||
|
||
WORKDIR /app | ||
|
||
COPY requirements.txt . | ||
|
||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
COPY ./src /app | ||
|
||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] |
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,10 @@ | ||
IMAGE_NAME=choisunguk/print-podname | ||
IMAGE_TAG=python-rc1.2 | ||
|
||
create-builder: | ||
docker buildx create --name mybuilder --use | ||
|
||
build-push: | ||
docker buildx build --platform linux/amd64,linux/arm64 -t $(IMAGE_NAME):${IMAGE_TAG} --push . | ||
|
||
.PHONY: create-builder build-push |
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,16 @@ | ||
# 개요 | ||
* pod name을 조회하는 API | ||
* python FasteAPI로 개발됨 | ||
|
||
# 배포 방법 | ||
|
||
```sh | ||
kubectl apply -f ./manifests/ | ||
``` | ||
|
||
# 호출 예제 | ||
|
||
```sh | ||
$ curl print-podname.default.svc.cluster.local; echo | ||
{"pod_name":"print-podname-576985bbff-pvtsb"}netshoot-597b97c87f-9wlt6 | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions
36
common_k8s_manifests/print_podname/manifests/deployment.yaml
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,36 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: print-podname | ||
namespace: default | ||
spec: | ||
replicas: 5 | ||
selector: | ||
matchLabels: | ||
app: print-podname | ||
template: | ||
metadata: | ||
labels: | ||
app: print-podname | ||
spec: | ||
containers: | ||
- name: print-podname | ||
image: choisunguk/print-podname:python-rc1.2 | ||
env: | ||
- name: POD_NAME | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.name | ||
resources: | ||
limits: | ||
memory: "64Mi" | ||
cpu: "50m" | ||
ports: | ||
- containerPort: 8000 | ||
topologySpreadConstraints: | ||
- maxSkew: 1 | ||
topologyKey: topology.kubernetes.io/zone | ||
whenUnsatisfiable: DoNotSchedule | ||
labelSelector: | ||
matchLabels: | ||
app: print-podname |
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,10 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: print-podname | ||
spec: | ||
selector: | ||
app: print-podname | ||
ports: | ||
- port: 80 | ||
targetPort: 8000 |
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,31 @@ | ||
annotated-types==0.6.0 | ||
anyio==4.3.0 | ||
certifi==2024.2.2 | ||
click==8.1.7 | ||
dnspython==2.6.1 | ||
email_validator==2.1.1 | ||
fastapi==0.110.3 | ||
h11==0.14.0 | ||
httpcore==1.0.5 | ||
httptools==0.6.1 | ||
httpx==0.27.0 | ||
idna==3.7 | ||
itsdangerous==2.2.0 | ||
Jinja2==3.1.3 | ||
MarkupSafe==2.1.5 | ||
orjson==3.10.2 | ||
pydantic==2.7.1 | ||
pydantic-extra-types==2.7.0 | ||
pydantic-settings==2.2.1 | ||
pydantic_core==2.18.2 | ||
python-dotenv==1.0.1 | ||
python-multipart==0.0.9 | ||
PyYAML==6.0.1 | ||
sniffio==1.3.1 | ||
starlette==0.37.2 | ||
typing_extensions==4.11.0 | ||
ujson==5.9.0 | ||
uvicorn==0.29.0 | ||
uvloop==0.19.0 | ||
watchfiles==0.21.0 | ||
websockets==12.0 |
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,10 @@ | ||
from fastapi import FastAPI | ||
import os | ||
from fastapi.responses import JSONResponse | ||
|
||
app = FastAPI() | ||
|
||
@app.get("/") | ||
def print_podname(): | ||
pod_name = os.getenv("POD_NAME", "unknown") | ||
return JSONResponse(content={"pod_name": pod_name}) |