-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CFGOV Helm Charts for Local Deployment to K8s #8683
Open
cooldragontattoo
wants to merge
20
commits into
main
Choose a base branch
from
cfgov-helmed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
eb121e3
add helm chart for cfgov
cooldragontattoo eadc561
add configuration for db and pgadmin
cooldragontattoo 4d282e4
Iterate to working
willbarton 7c578b2
Fixes with postgres
willbarton 4978dc7
update helm chart and scripts
cooldragontattoo aa437f3
Revert refresh-data noindex changes
chosak 0e8f524
add apache container
cooldragontattoo e0dfa9b
add apache configuration for helm deployment
cooldragontattoo 758c667
Remove unneeded dj-database-url fallback
chosak c28b40c
update helm chart to utilize opensearch
cooldragontattoo d7b3400
add docs, helm-uninstall and clean up values.yaml
cooldragontattoo d305d01
add apache image and remove apache volumes from values-yaml
cooldragontattoo 44b5734
remove python command
cooldragontattoo 03d7618
Update cfgov/apache/dockerfile
cooldragontattoo 5048fa7
update docker copy
cooldragontattoo de8af1f
disable use_ssl for opensearch
cooldragontattoo 6e991e8
add comments
cooldragontattoo 77895f5
Merge branch 'main' into cfgov-helmed
cooldragontattoo d37c4de
remove apache config files
cooldragontattoo 8558dca
Merge branch 'main' into cfgov-helmed
cooldragontattoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,24 @@ | ||
FROM httpd:2.4-alpine | ||
|
||
# Copy the Apache configuration file | ||
COPY ./conf /usr/local/apache2/conf | ||
COPY ./conf.d /usr/local/apache2/conf.d | ||
COPY ./conf.modules.d /usr/local/apache2/conf.modules.d | ||
|
||
# Add Apache ENV variables | ||
ENV APACHE_PORT="80" | ||
ENV APACHE_USER="www-data" | ||
ENV APACHE_GROUP="www-data" | ||
ENV APACHE_SERVER_ROOT="/usr/local/apache2/" | ||
ENV APACHE_UPLOADS_F_ALIAS="/src/consumerfinance.gov/cfgov/f/" | ||
ENV STATIC_PATH="/tmp" | ||
ENV ERROR_LOG="/proc/self/fd/2" | ||
ENV ACCESS_LOG="/proc/self/fd/1" | ||
ENV LIMIT_REQUEST_BODY="0" | ||
ENV APACHE_STATUS_ALLOW_FROM="127.0.0.1" | ||
ENV APACHE_PROCESS_COUNT="4" | ||
ENV CFGOV_APPLICATION_HOST="localhost" | ||
|
||
EXPOSE 80 | ||
|
||
CMD ["httpd-foreground"] |
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
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,106 @@ | ||
# Helm Deployment Guide | ||
|
||
This document provides a comprehensive guide to setting up, deploying, and uninstalling your Helm deployment. | ||
|
||
## Table of Contents | ||
|
||
1. [Introduction](#introduction) | ||
2. [Requirements](#requirements) | ||
3. [Helm Chart](#helm-chart) | ||
- [chart.yaml](#chartyaml) | ||
- [values.yaml](#valuesyaml) | ||
- [templates/NOTES.txt](#templatesnotestxt) | ||
4. [Deploying the Helm Chart](#deploying-the-helm-chart) | ||
5. [Uninstalling the Helm Deployment](#uninstalling-the-helm-deployment) | ||
|
||
## Introduction | ||
|
||
This guide explains the setup and deployment process for the CFPB Helm Chart, which includes PostgreSQL, OpenSearch, and the CFGOV application. The Helm chart is configured to support local deployments. | ||
|
||
## Requirements | ||
|
||
1. **Local Kubernetes Cluster**: | ||
- Ensure you have a local Kubernetes cluster running. We only support [Docker Desktop](https://www.docker.com/products/docker-desktop) and [colima](https://github.com/abiosoft/colima). | ||
|
||
2. **kubectl**: | ||
- Install `kubectl`, the Kubernetes command-line tool, by following the [official installation guide](https://kubernetes.io/docs/tasks/tools/install-kubectl/). | ||
|
||
3. **Helm**: | ||
- Install Helm, the package manager for Kubernetes, by following the [official installation guide](https://helm.sh/docs/intro/install/). | ||
|
||
|
||
## Helm Chart | ||
|
||
### chart.yaml | ||
|
||
In our `chart.yaml` we bring two Helm chart dependencies: | ||
|
||
- Opensearch | ||
- Postgresql | ||
|
||
### values.yaml | ||
|
||
The `values.yaml` file contains our local configuration for the deployment of CFGOV. | ||
|
||
#### Init Containers | ||
We have two init containers: | ||
|
||
1. Busybox: | ||
- Starts up once we have our Postgresql and Opensearch Pods running. | ||
- Serves as a pre-cursor to our cfgov-migrations container. | ||
|
||
2. cfgov-migrations | ||
- Runs the django migrations and the `refresh-data.sh` script and populates it with test data `test.sql.gz`. | ||
- Indexes our database to Opensearch. | ||
|
||
#### Containers | ||
|
||
1. cfgov: | ||
- Uses the cfgov image, found in the repo's root `dockerfile` | ||
- Serves up our Django application on Port 8000 of the cfgov pod | ||
|
||
2. cfgov-apache: | ||
- Built from `cfgov-apache` image built from the `apache/dockerfile` | ||
- Serves as a webserver to proxy to our cfgov container | ||
|
||
|
||
### notes.txt | ||
|
||
Our [notes.txt](https://helm.sh/docs/chart_template_guide/notes_files/) is split to work for local deployments and deployments to production. | ||
|
||
```txt | ||
{{- if .Values.localDeployment }} | ||
{{ .Files.Get "notes/NOTES-local.txt" }} | ||
{{- else }} | ||
{{ .Files.Get "notes/NOTES-production.txt" }} | ||
{{- end }} | ||
``` | ||
|
||
## Deploying the CFGOV Helm Chart | ||
|
||
Deploying the CFGOV Helm chart is simple with the `helm-init.sh` script. | ||
|
||
To deploy the CFGOV Helm Chart you must: | ||
1. make sure you have a the cfgov and cfgov-apache image built | ||
2. have a local K8s cluster running (docker desktop, colima) | ||
|
||
If these criteria are not met, the `helm-init.sh` script will not run. | ||
|
||
## Viewing the Helm Chart | ||
|
||
You can either user a K8s IDE ([lens](https://k8slens.dev/), [k9s](https://k9scli.io)) or manually portfward to view the application running. | ||
|
||
Review the output of your deployment for more information on manually portforwarding. | ||
|
||
|Pod|Container|Port| | ||
|-|-|-| | ||
|cfgov|cfgov|8000| | ||
|cfgov|cfogv-apache|80| | ||
|postgresql|postgresql|5432| | ||
|opensearch|opensearch|9200 (http)| | ||
| | | 9300 (transport)| | ||
| | | 9600 (metrics) | ||
|
||
## Uninstall the CFGOV Helm Chart | ||
|
||
Running `helm-uninstall.sh` will uninstall the helm deploymennt of the CFGOV Helm Chart, as well as remove Persistent Volume Claims for the Open Search Pod and the Postgresql Pod. |
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,92 @@ | ||
#!/bin/bash | ||
|
||
# Define color codes for pretty output | ||
RED='\033[0;31m' | ||
GREEN='\033[0;32m' | ||
YELLOW='\033[1;33m' | ||
NC='\033[0m' # No Color | ||
|
||
OUTPUT_FILE=$(mktemp) | ||
|
||
# Check if helm is installed | ||
if ! command -v helm &> /dev/null; then | ||
echo -e "${RED}Helm could not be found. Please install it before running this script.${NC}" | ||
exit 1 | ||
fi | ||
|
||
# Check if kubectl is installed | ||
if ! command -v kubectl &> /dev/null; then | ||
echo -e "${RED}Kubectl could not be found. Please install it before running this script.${NC}" | ||
exit 1 | ||
fi | ||
|
||
if ! docker images | grep -q "cfgov"; then | ||
echo -e "${RED}Docker images 'cfgov' could not be found." | ||
docker build . -t cfgov | ||
fi | ||
|
||
if ! docker images | grep -q "cfgov-apache"; then | ||
echo -e "${RED}Docker images 'cfgov-apache' could not be found." | ||
docker build ./cfgov/apache/. -t cfgov-apache | ||
fi | ||
|
||
# Get the current Kubernetes cluster context | ||
CLUSTER=$(kubectl config current-context) | ||
|
||
# Check if a Kubernetes cluster is configured | ||
if [ -z "$CLUSTER" ]; then | ||
echo -e "${RED}No Kubernetes cluster is currently configured. Please configure a cluster before running this script.${NC}" | ||
exit 1 | ||
fi | ||
|
||
echo -e "${GREEN}Current Kubernetes cluster: $CLUSTER${NC}" | ||
|
||
# Check if the current cluster is a local cluster (docker-desktop or colima) | ||
if [[ "$CLUSTER" != "docker-desktop" && "$CLUSTER" != "colima" ]]; then | ||
echo -e "${YELLOW}" | ||
echo -e "This script is intended to be run on a local Kubernetes cluster (i.e. docker-desktop or colima)." | ||
echo -e "Your current cluster is ${RED}$CLUSTER${YELLOW}." | ||
echo -e "Please switch to docker-desktop or colima before running this script." | ||
echo -e "${NC}" | ||
echo -e "${RED}Exiting helm-init${NC}" | ||
exit 1 | ||
fi | ||
|
||
# Define the Helm directory | ||
HELM_DIR="./helm" | ||
|
||
|
||
# Check if the ./cfgov/apache directory exists | ||
if [ -d "./cfgov/apache" ]; then | ||
echo -e "${GREEN}Moving ./cfgov/apache to $HELM_DIR${NC}" | ||
cp -r ./cfgov/apache $HELM_DIR | ||
else | ||
echo -e "${RED}Directory ./cfgov/apache does not exist.${NC}" | ||
exit 1 | ||
fi | ||
|
||
# Check if the ./helm/charts directory exists | ||
if [ ! -d "./helm/charts" ]; then | ||
echo -e "${GREEN}Building Helm charts...${NC}" | ||
helm dependency update $HELM_DIR | ||
helm dependency build $HELM_DIR | ||
else | ||
# Update Helm dependencies if SKIP_DEP_UPDATE is not set | ||
if [ -z "$SKIP_DEP_UPDATE" ]; then | ||
echo -e "${GREEN}Updating Helm dependencies...${NC}" | ||
helm dependency update $HELM_DIR | ||
fi | ||
fi | ||
|
||
# Upgrade or install the Helm release | ||
echo -e "${GREEN}Upgrading/Installing Helm release...${NC}" | ||
helm upgrade --install cfgov $HELM_DIR -f $HELM_DIR/values.local.yaml >> $OUTPUT_FILE 2>&1 | ||
|
||
# Remove the copied apache directory | ||
echo -e "${GREEN}Cleaning up...${NC}" | ||
rm -r $HELM_DIR/apache | ||
|
||
echo -e "${GREEN}Helm initialization script completed successfully.${NC}" | ||
|
||
cat $OUTPUT_FILE | ||
rm $OUTPUT_FILE |
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,38 @@ | ||
#!/bin/bash | ||
|
||
# Define color codes for pretty output | ||
RED='\033[0;31m' | ||
GREEN='\033[0;32m' | ||
NC='\033[0m' # No Color | ||
|
||
# Check if helm is installed | ||
if ! command -v helm &> /dev/null; then | ||
echo -e "${RED}Helm could not be found. Please install it before running this script.${NC}" | ||
exit 1 | ||
fi | ||
|
||
# Define the release name and namespace | ||
RELEASE_NAME="cfgov" | ||
NAMESPACE="default" | ||
|
||
# Uninstall the Helm release | ||
echo -e "${GREEN}Uninstalling Helm release ${RELEASE_NAME}...${NC}" | ||
helm uninstall $RELEASE_NAME --namespace $NAMESPACE | ||
|
||
# Uninstall the PVCs for the PostgreSQL and OpenSearch pods | ||
kubectl delete pvc data-cfgov-postgresql-0 --namespace $NAMESPACE | ||
kubectl delete pvc opensearch-cluster-master-opensearch-cluster-master-0 --namespace $NAMESPACE | ||
|
||
# Check if the uninstall was successful | ||
if [ $? -eq 0 ]; then | ||
echo -e "${GREEN}Helm release ${RELEASE_NAME} uninstalled successfully.${NC}" | ||
else | ||
echo -e "${RED}Failed to uninstall Helm release ${RELEASE_NAME}.${NC}" | ||
exit 1 | ||
fi | ||
|
||
# Optionally, delete the namespace if it was created specifically for this release | ||
# echo -e "${GREEN}Deleting namespace ${NAMESPACE}...${NC}" | ||
# kubectl delete namespace $NAMESPACE | ||
|
||
echo -e "${GREEN}Helm uninstallation script completed successfully.${NC}" |
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,23 @@ | ||
# Patterns to ignore when building packages. | ||
# This supports shell glob matching, relative path matching, and | ||
# negation (prefixed with !). Only one pattern per line. | ||
.DS_Store | ||
# Common VCS dirs | ||
.git/ | ||
.gitignore | ||
.bzr/ | ||
.bzrignore | ||
.hg/ | ||
.hgignore | ||
.svn/ | ||
# Common backup files | ||
*.swp | ||
*.bak | ||
*.tmp | ||
*.orig | ||
*~ | ||
# Various IDEs | ||
.project | ||
.idea/ | ||
*.tmproj | ||
.vscode/ |
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 @@ | ||
dependencies: | ||
- name: postgresql | ||
repository: https://charts.bitnami.com/bitnami | ||
version: 16.2.3 | ||
- name: opensearch | ||
repository: https://opensearch-project.github.io/helm-charts/ | ||
version: 1.31.3 | ||
digest: sha256:9a8a22b89a2f2c3c3d9ab178dc0b751c75d95e37215baf42a27b80982469efe0 | ||
generated: "2024-12-10T15:35:50.786246-07:00" |
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,23 @@ | ||
apiVersion: v2 | ||
name: cfgov | ||
description: A Helm chart for consumerfinance.gov | ||
type: application | ||
|
||
# This is the chart version. This version number should be incremented each time you make changes | ||
# to the chart and its templates, including the app version. | ||
# Versions are expected to follow Semantic Versioning (https://semver.org/) | ||
version: 0.1.0 | ||
|
||
# This is the version number of the application being deployed. This version number should be | ||
# incremented each time you make changes to the application. Versions are not expected to | ||
# follow Semantic Versioning. They should reflect the version the application is using. | ||
# It is recommended to use it with quotes. | ||
appVersion: "1.16.0" | ||
|
||
dependencies: | ||
- name: postgresql | ||
version: 16.2.3 | ||
repository: https://charts.bitnami.com/bitnami | ||
- name: opensearch | ||
version: 1.31.3 | ||
repository: https://opensearch-project.github.io/helm-charts/ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is missing