Skip to content

Commit

Permalink
refactor: simplify k8s project
Browse files Browse the repository at this point in the history
feat: add minikube
  • Loading branch information
gm112 committed Jan 12, 2025
1 parent 775e107 commit 8813998
Show file tree
Hide file tree
Showing 42 changed files with 502 additions and 302 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/k8s-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# name: Kubernetes Deployment

# on:
# push:
# branches:
# - main

# jobs:
# deploy:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - name: Set up Kubernetes CLI
# uses: azure/setup-kubectl@v1
# with:
# version: 'v1.21.0'
# - name: Create MySQL and PostgreSQL Secrets
# run: |
# echo "$MYSQL_PASSWORD" | base64 | kubectl create secret generic mysql-secret \
# --from-literal=password=- \
# --dry-run=client -o yaml | kubectl apply -f -
# echo "$POSTGRES_PASSWORD" | base64 | kubectl create secret generic postgres-secret \
# --from-literal=password=- \
# --dry-run=client -o yaml | kubectl apply -f -
# env:
# MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
# POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
# - name: Deploy
# run: |
# export $(cat kustomize.env | xargs) # Load and export env vars
# kustomize build base | kubectl apply -f -
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ build/

### VS Code ###
.vscode/
dist/
iac/**/.env
64 changes: 49 additions & 15 deletions iac/README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,59 @@
# Infrastructure as Code
# zfgc.com

This directory contains the infrastructure as code for the ZFGCBB project.
Pizza.

## Table of Contents
## Environment Setup

- [Infrastructure as Code](#infrastructure-as-code)
- [Table of Contents](#table-of-contents)
- [Requirements](#requirements)
- [Getting Started](#getting-started)
- [License](#license)
### Install Dependencies

## Requirements
```bash
cd iac/zfgc.com
./scripts/bootstrap.sh
```

- [Docker](https://docs.docker.com/get-docker/)
- [Kubectl](https://kubernetes.io/docs/tasks/tools/)
- [Kustomize](https://kustomize.io/)
1. **Docker**: Ensure Docker is installed to build/test containers locally - [Get Docker](https://docs.docker.com/get-docker/).

## Getting Started
### Project Configuration

For now, just look at [](zfgc.com/kube/README.md)
1. **Secrets Management**:
- Store sensitive data like database passwords securely.
- Add MySQL and PostgreSQL passwords as secrets in your GitHub repository:

- **MySQL Password**: Under `Settings > Secrets and variables > Actions > New repository secret`.
- Name: `MYSQL_PASSWORD`
- Value: Your MySQL password.

- **PostgreSQL Password**: Under `Settings > Secrets and variables > Actions > New repository secret`.
- Name: `POSTGRES_PASSWORD`
- Value: Your PostgreSQL password.

## Deployment Process

### Deploying Locally with minikube

Run the following command to start minikube:

```bash
./iac/zfgc.com/scripts/start-minikube.sh

./iac/zfgc.com/scripts/setup-test.sh
```

## Notes

- **Customizing Values**:
Modify `kustomize.env` and environment-specific overlays as needed for different settings.

- **Service Endpoints**:
Verify networking settings to ensure appropriate service access.

- **Troubleshooting**:
Check logs using `kubectl logs` for any deployment-related issues.

## Contributions

Feel free to contribute to the project by forking the repository, making changes, and submitting a pull request.

## License

This project is licensed under the MIT License - see the [LICENSE](../LICENSE) file for details.
This project is licensed under the MIT License.
File renamed without changes.
17 changes: 17 additions & 0 deletions iac/zfgc.com/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Namespace for isolation
NAMESPACE=dev

# File paths for services
MYSQL_DIRECTORY=./dist/old-skool/mysql_data
POSTGRES_DIRECTORY=./dist/zfg-bb/postgres_data
APACHE_VHOST_CONFIG_DIRECTORY=./dist/old-skool/apache_vhosts

# Secure MySQL and PostgreSQL passwords (set secure values in production)
MYSQL_PASSWORD=your_mysql_password
POSTGRES_PASSWORD=your_postgres_password

# Apache Vhost config directory
APACHE_VHOST_CONFIG_DIRECTORY=./dist/old-skool/apache_vhosts

# Image name for zfg-bb (Spring Java project)
ZFGBB_IMAGE_NAME=zfg-bb:latest
33 changes: 33 additions & 0 deletions iac/zfgc.com/base/deployment-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
namespace: $(NAMESPACE)
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:16
env:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-secret
key: password
ports:
- containerPort: 5432
volumeMounts:
- mountPath: /var/lib/postgresql/data
name: postgres-vol
volumes:
- name: postgres-vol
hostPath:
path: $(postgres.directory)
37 changes: 37 additions & 0 deletions iac/zfgc.com/base/ingress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
namespace: my-namespace
spec:
rules:
- host: zfgc.com
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: old-skool
port:
number: 80
- host: crystalrook.com
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: old-skool
port:
number: 80
- host: pizzatime.zfgc.com
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: zfg-bb
port:
number: 80
38 changes: 38 additions & 0 deletions iac/zfgc.com/base/kustomization.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace: $(NAMESPACE)

resources:
- namespace.yaml
- old-skool/
- zfg-bb/

configMapGenerator:
- literals:
- apache.directory=$(APACHE_DIRECTORY)
- mysql.directory=$(MYSQL_DIRECTORY)
name: old-skool-config
- literals:
- postgres.directory=$(POSTGRES_DIRECTORY)
name: zfg-bb-config

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
replacements:
- source:
kind: Namespace
name: $(NAMESPACE)
version: v1
- source:
fieldPath: data.apache.directory
kind: ConfigMap
name: old-skool-config
version: v1
- source:
fieldPath: data.mysql.directory
kind: ConfigMap
name: old-skool-config
version: v1
- source:
fieldPath: data.postgres.directory
kind: ConfigMap
name: zfg-bb-config
version: v1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: ${NAMESPACE}
name: $(NAMESPACE)
8 changes: 8 additions & 0 deletions iac/zfgc.com/base/secret-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: postgres-secret
namespace: $(NAMESPACE)
type: Opaque
data:
password: <base64_encoded_password>
11 changes: 11 additions & 0 deletions iac/zfgc.com/base/service-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: postgres
namespace: $(NAMESPACE)
spec:
ports:
- port: 5432
targetPort: 5432
selector:
app: postgres
21 changes: 21 additions & 0 deletions iac/zfgc.com/environments/development/kustomization.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
resources:
- ../../base
- ../../services/zfg-bb

namespace: dev-${NAMESPACE}

configMapGenerator:
- literals:
- hostDir=/dev/path/to/tomcat
name: tomcat-config
- literals:
- hostDir=/dev/path/to/postgres
name: postgres-config

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
replacements:
- source:
fieldPath: metadata.name
kind: Namespace
name: dev-${NAMESPACE}
39 changes: 39 additions & 0 deletions iac/zfgc.com/environments/production/kustomization.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
resources:
- ../../base
- ../../services

namespace: prod-${NAMESPACE}

configMapGenerator:
- literals:
- hostDir=/prod/path/to/apache
name: apache-config
- literals:
- hostDir=/prod/path/to/mysql
name: mysql-config
- literals:
- hostDir=/prod/path/to/tomcat
name: tomcat-config
- literals:
- hostDir=/prod/path/to/postgres
name: postgres-config

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
patches:
- patch: |
- op: remove
path: /spec/rules/0
- op: remove
path: /spec/rules/1
target:
group: networking.k8s.io
kind: Ingress
name: my-ingress
version: v1
replacements:
- source:
fieldPath: metadata.name
kind: Namespace
name: prod-${NAMESPACE}

21 changes: 0 additions & 21 deletions iac/zfgc.com/kube/README.md

This file was deleted.

Loading

0 comments on commit 8813998

Please sign in to comment.