from flask import Flask, jsonify
import time
PORT = 8080
app = Flask(__name__)
@app.route("/")
def root():
return jsonify({"App Status" : "Running"})
@app.route("/getTime")
def getTime():
seconds = time.time()
local_time = time.localtime(seconds)
return jsonify({"Year" : local_time.tm_year,"Seconds" : seconds, "Local Time" : local_time})
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=PORT)
flask
FROM python:3.7
RUN mkdir /app
WORKDIR /app
ADD . /app/
RUN pip install -r requirements.txt
CMD ["python", "/app/app.py"]
git config --global user.name <<GitHubUserName>>
git config --global user.email <<GitHubEmailID>>
git config --global user.password <<GitHubAccessToken>>
kubectl config set-context --current --namespace=<insert-namespace-name-here>
kubectl config view --minify | grep namespace:
kubectl create secret docker-registry py-regcred\
--namespace default \
--docker-server=ghcr.io \
--docker-email=<<GitHubEmailID>> \
--docker-username=<<GitHubUserName>> \
--docker-password=<<GitHubAccessToken>>
kubectl create secret docker-registry regcred \
--namespace default \
--docker-server=docker.io \
--docker-email=<<DockerEmailID>> \
--docker-username=<<DockerUserName>> \
--docker-password=<<DockerPassword>>
docker build . --tag ghcr.io/<<GITHubUserID>>/py-flask-kubernetes:latest
docker build . --tag ghcr.io/sainithesh/py-flask-kubernetes:latest
docker run ghcr.io/sainithesh/py-flask-kubernetes:latest
docker build . --tag docker.io/sainithesh/py-flask-kubernetes:latest
docker run docker.io/sainithesh21/py-flask-kubernetes:latest
docker push ghcr.io/sainithesh/py-flask-kubernetes:latest
docker push docker.io/sainithesh21/py-flask-kubernetes:latest
apiVersion: apps/v1
kind: Deployment
metadata:
name: py-flask-kubernetes
labels:
app: py-flask-kubernetes
spec:
selector:
matchLabels:
app: py-flask-kubernetes
replicas: 1
template:
metadata:
labels:
app: py-flask-kubernetes
spec:
containers:
- name: py-flask-kubernetes
image: ghcr.io/sainithesh/py-flask-kubernetes:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
resources:
limits:
ephemeral-storage: 256M
memory: 256M
cpu: 100m
requests:
ephemeral-storage: 256M
memory: 256M
cpu: 100m
imagePullSecrets:
- name: py-regcred
status: {}
---
apiVersion: v1
kind: Service
metadata:
name: py-flask-kubernetes
spec:
selector:
app: py-flask-kubernetes
ports:
- protocol: "TCP"
port: 8081
targetPort: 8080
---
apiVersion: gateway.kyma-project.io/v1alpha1
kind: APIRule
metadata:
name: py-flask-kubernetes
spec:
gateway: kyma-gateway.kyma-system.svc.cluster.local
service:
name: py-flask-kubernetes
port: 8081
host: py-flask-kubernetes
rules:
- path: /.*
methods: ["GET"]
accessStrategies:
- handler: noop
config: {}
kubectl apply -n default -f deployment.yaml
name: Build and Push Docker Imag
on: [push]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build_and_push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
buildkitd-flags: --debug
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.PKG_SECRET }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build the py-flask-kubernetes Docker image
uses: docker/build-push-action@v3.0.0
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
9 | |
7 | |
6 | |
6 | |
6 | |
6 | |
5 | |
5 | |
4 |