You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Create a folder for the Kubernetes deployment files
mkdir -p $HOME/RestQR/deploy/kubernetes
# Create a values file for the Ingress controller
cat <<EOF >$HOME/RestQR/deploy/kubernetes/ingress-values.yamlcontroller: service: type: LoadBalancerEOF
# Wait for the external IP address to be assignedwhiletrue;do
INGRESS_IP=$(kubectl get svc ingress-nginx-controller \ -o jsonpath='{.status.loadBalancer.ingress[0].ip}')if [[ -n"$INGRESS_IP" ]];thenbreakfi
sleep 2
done# Export the Ingress IP address as an environment variableecho"export INGRESS_IP=$INGRESS_IP">>~/.bashrc
source~/.bashrc
cat <<EOF >$HOME/RestQR/deploy/kubernetes/menu-deployment.yamlapiVersion: apps/v1kind: Deploymentmetadata:
# Name of the Deploymentname: menu labels:
# Label to identify the applicationapp: menu spec:
# Number of desired pod replicas (1 instance of the menu service)replicas: 1selector:
matchLabels:
# Ensures that the Deployment manages pods with this labelapp: menu template:
metadata:
labels:
# Label assigned to the pod created by this templateapp: menu spec:
containers:
# Name of the container inside the pod
- name: menu # Image location from GitLab Container Registryimage: $GITLAB_REGISTRY_URL/menu-service:v0.1.0 # Always pull the image from the registryimagePullPolicy: Alwaysports:
# The application inside the container listens on port 5000
- containerPort: 5000env:
# Environment variable for database connection
- name: DATABASE_URL valueFrom:
secretKeyRef:
# Reference to the Kubernetes secret containing the database URLname: menu-secret # The specific key inside the secretkey: DATABASE_URL # Image Pull Secret for GitLab Container Registry authenticationimagePullSecrets:
# Kubernetes secret containing GitLab credentials
- name: gitlab-registry-secret EOF
# Run this only if you don't have the config.json file
mkdir -p $HOME/.docker && cat <<EOF >$HOME/.docker/config.json{ "auths": { "registry.gitlab.com": { "auth": "$(echo -n "$GITLAB_USERNAME:$GITLAB_API_TOKEN"| base64 -w 0)" } }}EOF
cat <<EOF >$HOME/RestQR/deploy/kubernetes/postgresql-values.yamlglobal:
imagePullSecrets:
- name: gitlab-registry-secretsecurity:
allowInsecureImages: trueauth:
existingSecret: menu-postgres-secret# Custom PostgreSQL user for the menu serviceusername: menu-user # Database name for the menu servicedatabase: menu-databasesecretKeys:
# Key for the PostgreSQL admin passwordadminPasswordKey: postgres-password# Key for the PostgreSQL custom user passworduserPasswordKey: menu-password primary:
persistence:
enabled: truesize: 8Gi extendedConfiguration: | listen_addresses = '*' max_connections = 200 image:
registry: $GITLAB_REGISTRY_URLrepository: menu-postgresqltag: v0.1.0service:
type: ClusterIPports:
postgresql: 5432architecture: "standalone"EOF
# Create a secret for the PostgreSQL instancecat <<EOF >$HOME/RestQR/deploy/kubernetes/postgresql-secret.yamlapiVersion: v1kind: Secretmetadata:
name: menu-postgres-secrettype: Opaquedata:
postgres-password: $(echo -n "postgres-password" | base64 -w 0)menu-password: $(echo -n "menu-password" | base64 -w 0) EOF# Apply the secretkubectl apply \-f $HOME/RestQR/deploy/kubernetes/postgresql-secret.yaml
helm upgrade --install \
menu \
bitnami/postgresql \
-f $HOME/RestQR/deploy/kubernetes/postgresql-values.yaml
cat <<EOF >$HOME/RestQR/deploy/kubernetes/ingress.yamlapiVersion: networking.k8s.io/v1kind: Ingressmetadata:
name: restqr-ingressannotations:
# Ensures that all requests are rewritten to the root pathnginx.ingress.kubernetes.io/rewrite-target: / spec:
# Specifies that the Ingress will be managed by the NGINX Ingress ControlleringressClassName: nginx # List of rulesrules:
# Defines the hostname for the menu service
- host: menu.$INGRESS_IP.sslip.io http:
paths:
# Matches all requests under this path
- path: / # Ensures all subpaths are includedpathType: Prefix backend:
service:
# Redirects traffic to the menu servicename: menu port:
# Specifies the port the menu service is listening onnumber: 5000# Defines the hostname for the QR service
- host: qr.$INGRESS_IP.sslip.io http:
paths:
- path: / pathType: Prefixbackend:
service:
# Redirects traffic to the QR servicename: qrport:
# Specifies the port the QR service is listening onnumber: 5001EOF
cat <<EOF >>$HOME/RestQR/.gitignore# Ignore the menu secret filemenu-secret.yamlEOF
cat <<EOF >>$HOME/RestQR/.gitignore# Ignore the PostgreSQL secret filepostgresql-secret.yamlEOF
cd$HOME/RestQR
git add .
git commit -m "Kubernetes YAML, Helm values, and ignored sensitive files"
git push origin main
Rewriting the Git History to Remove Sensitive Data
cd$HOME/RestQR
# Install git-filter-repo on your machine# Deactivate the virtual environment if you are using one
deactivate
# Launch the installation
pip install \
git-filter-repo \
--break-system-packages
# To complete remove the file from the repository history, # you need to run the following command:
git-filter-repo \
--invert-paths \
--path deploy/kubernetes/menu-secret.yaml \
--force
# The above command removes the origin, re-add it using the following command:
git remote add origin \
git@$GITLAB_INSTANCE:$GITLAB_GROUP/$GITLAB_PROJECT# Push the changes to the repository
git push origin --force --all
git push origin --force --tags