Refactor Kubernetes deployment process to use manifest files and environment variable substitution
This commit is contained in:
72
.github/workflows/deploy.yml
vendored
72
.github/workflows/deploy.yml
vendored
@@ -49,67 +49,17 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
export KUBECONFIG=kubeconfig
|
export KUBECONFIG=kubeconfig
|
||||||
|
|
||||||
# Create deployment
|
# Replace variables in manifests and apply
|
||||||
cat <<EOF | kubectl apply -f -
|
for manifest in k8s/*.yaml; do
|
||||||
apiVersion: apps/v1
|
envsubst < "$manifest" | kubectl apply -f -
|
||||||
kind: Deployment
|
done
|
||||||
metadata:
|
env:
|
||||||
name: ${{ env.APP_NAME }}
|
APP_NAME: ${{ env.APP_NAME }}
|
||||||
namespace: ${{ env.NAMESPACE }}
|
NAMESPACE: ${{ env.NAMESPACE }}
|
||||||
labels:
|
REGISTRY: ${{ env.REGISTRY }}
|
||||||
app: ${{ env.APP_NAME }}
|
IMAGE_NAME: ${{ env.IMAGE_NAME }}
|
||||||
spec:
|
IMAGE_TAG: ${{ inputs.image_tag }}
|
||||||
replicas: 2
|
HOST: ${{ env.HOST }}
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app: ${{ env.APP_NAME }}
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: ${{ env.APP_NAME }}
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: ${{ env.APP_NAME }}
|
|
||||||
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.image_tag }}
|
|
||||||
ports:
|
|
||||||
- containerPort: 5173
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
memory: "256Mi"
|
|
||||||
cpu: "250m"
|
|
||||||
limits:
|
|
||||||
memory: "512Mi"
|
|
||||||
cpu: "500m"
|
|
||||||
---
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
name: ${{ env.APP_NAME }}-service
|
|
||||||
namespace: ${{ env.NAMESPACE }}
|
|
||||||
spec:
|
|
||||||
selector:
|
|
||||||
app: ${{ env.APP_NAME }}
|
|
||||||
ports:
|
|
||||||
- protocol: TCP
|
|
||||||
port: 80
|
|
||||||
targetPort: 5173
|
|
||||||
type: ClusterIP
|
|
||||||
---
|
|
||||||
apiVersion: traefik.containo.us/v1alpha1
|
|
||||||
kind: IngressRoute
|
|
||||||
metadata:
|
|
||||||
name: ${{ env.APP_NAME }}-ingress
|
|
||||||
namespace: ${{ env.NAMESPACE }}
|
|
||||||
spec:
|
|
||||||
entryPoints:
|
|
||||||
- web
|
|
||||||
routes:
|
|
||||||
- match: Host(\`${{ env.HOST }}\`)
|
|
||||||
kind: Rule
|
|
||||||
services:
|
|
||||||
- name: ${{ env.APP_NAME }}-service
|
|
||||||
port: 80
|
|
||||||
EOF
|
|
||||||
|
|
||||||
- name: Verify deployment
|
- name: Verify deployment
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
29
k8s/deployment.yaml
Normal file
29
k8s/deployment.yaml
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: ${APP_NAME}
|
||||||
|
namespace: ${NAMESPACE}
|
||||||
|
labels:
|
||||||
|
app: ${APP_NAME}
|
||||||
|
spec:
|
||||||
|
replicas: 2
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: ${APP_NAME}
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: ${APP_NAME}
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: ${APP_NAME}
|
||||||
|
image: ${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}
|
||||||
|
ports:
|
||||||
|
- containerPort: 5173
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: "256Mi"
|
||||||
|
cpu: "250m"
|
||||||
|
limits:
|
||||||
|
memory: "512Mi"
|
||||||
|
cpu: "500m"
|
||||||
21
k8s/ingress.yaml
Normal file
21
k8s/ingress.yaml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: ${APP_NAME}-ingress
|
||||||
|
namespace: ${NAMESPACE}
|
||||||
|
labels:
|
||||||
|
app: ${APP_NAME}
|
||||||
|
annotations:
|
||||||
|
traefik.ingress.kubernetes.io/router.entrypoints: web
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- host: ${HOST}
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: ${APP_NAME}-service
|
||||||
|
port:
|
||||||
|
number: 80
|
||||||
13
k8s/service.yaml
Normal file
13
k8s/service.yaml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: ${APP_NAME}-service
|
||||||
|
namespace: ${NAMESPACE}
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: ${APP_NAME}
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 80
|
||||||
|
targetPort: 5173
|
||||||
|
type: ClusterIP
|
||||||
Reference in New Issue
Block a user