From 1a11087e6f2799a2596f6f4f1f0bfa14c76a542a Mon Sep 17 00:00:00 2001 From: Coding For Entrepreneurs Date: Tue, 25 Apr 2023 14:05:01 -0500 Subject: [PATCH 01/40] Create Dockerfile --- Dockerfile | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3f4bcf4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.11 + +COPY ./src /app +WORKDIR /app + +RUN pip install -r requirements.txt + +CMD ["python", "-m", "http.server", "8080"] From dcf5135e969c48e672ea7b7b89a395d795f319c5 Mon Sep 17 00:00:00 2001 From: Coding For Entrepreneurs Date: Tue, 25 Apr 2023 14:05:57 -0500 Subject: [PATCH 02/40] Create container-builld-push.yaml --- .github/workflows/container-builld-push.yaml | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/container-builld-push.yaml diff --git a/.github/workflows/container-builld-push.yaml b/.github/workflows/container-builld-push.yaml new file mode 100644 index 0000000..a59b10e --- /dev/null +++ b/.github/workflows/container-builld-push.yaml @@ -0,0 +1,29 @@ +name: Build Docker Container & Push to Docker Hub + +on: + workflow_dispatch: + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + 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 + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build web container image + run: | + docker build -f Dockerfile \ + -t jmitchel3/tf-python:latest \ + -t jmitchel3/f-python:${GITHUB_SHA::7}-${GITHUB_RUN_ID::5} \ + . + - name: Push container + run: | + docker push jmitchel3/tf-python --all-tags From 10ae064fefb54d5469b6be6cdc4e4b1d969ba038 Mon Sep 17 00:00:00 2001 From: Coding For Entrepreneurs Date: Tue, 25 Apr 2023 14:06:21 -0500 Subject: [PATCH 03/40] Create tf-python-manifest.yaml --- opts/tf-python-manifest.yaml | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 opts/tf-python-manifest.yaml diff --git a/opts/tf-python-manifest.yaml b/opts/tf-python-manifest.yaml new file mode 100644 index 0000000..1467965 --- /dev/null +++ b/opts/tf-python-manifest.yaml @@ -0,0 +1,38 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: tf-python +spec: + replicas: 3 + selector: + matchLabels: + app: tf-python + template: + metadata: + labels: + app: tf-python + spec: + containers: + - name: tf-python + image: jmitchel3/tf-python:latest + ports: + - containerPort: 8080 + env: + - name: PORT + value: "8080" + - name: ENV_MESSAGE + value: "Hello from Kubernetes" + +--- +apiVersion: v1 +kind: Service +metadata: + name: tf-python +spec: + type: LoadBalancer + ports: + - port: 80 + targetPort: 8080 + protocol: TCP + selector: + app: tf-python From acffb91530da44fd129e9b789f55ee00b1057c8d Mon Sep 17 00:00:00 2001 From: Coding For Entrepreneurs Date: Tue, 25 Apr 2023 14:06:38 -0500 Subject: [PATCH 04/40] Rename opts/tf-python-manifest.yaml to ops/tf-python-manifest.yaml --- {opts => ops}/tf-python-manifest.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {opts => ops}/tf-python-manifest.yaml (100%) diff --git a/opts/tf-python-manifest.yaml b/ops/tf-python-manifest.yaml similarity index 100% rename from opts/tf-python-manifest.yaml rename to ops/tf-python-manifest.yaml From ba25a87998a342790f5b04fe1437741396aec862 Mon Sep 17 00:00:00 2001 From: Coding For Entrepreneurs Date: Tue, 25 Apr 2023 14:07:08 -0500 Subject: [PATCH 05/40] Create k8s-apply.yaml --- .github/workflows/k8s-apply.yaml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/k8s-apply.yaml diff --git a/.github/workflows/k8s-apply.yaml b/.github/workflows/k8s-apply.yaml new file mode 100644 index 0000000..2479dac --- /dev/null +++ b/.github/workflows/k8s-apply.yaml @@ -0,0 +1,28 @@ +name: Apply Kubectl +on: + workflow_dispatch: + +jobs: + apply_k8s: + name: Verify K8s Service Account + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - uses: azure/setup-kubectl@v3 + - name: Create/Verify `.kube` directory + run: mkdir -p ~/.kube/ + - name: Create kubectl config + run: | + cat << EOF >> ~/.kube/kubeconfig.yaml + ${{ secrets.KUBECONFIG }} + EOF + - name: Apply Kubernetes Config + run: | + KUBECONFIG=~/.kube/kubeconfig.yaml kubectl apply -f ops/ + - name: Echo deployments + run: | + KUBECONFIG=~/.kube/kubeconfig.yaml kubectl get deployments + - name: Echo Services + run: | + KUBECONFIG=~/.kube/kubeconfig.yaml kubectl get services From 38cf146243220dd7e8398ff981bff53c837b9a59 Mon Sep 17 00:00:00 2001 From: Coding For Entrepreneurs Date: Wed, 26 Apr 2023 08:16:59 -0500 Subject: [PATCH 06/40] Delete Dockerfile --- Dockerfile | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 3f4bcf4..0000000 --- a/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM python:3.11 - -COPY ./src /app -WORKDIR /app - -RUN pip install -r requirements.txt - -CMD ["python", "-m", "http.server", "8080"] From 8d4c7a89ea5a2ad1ac7d868db331fcb347cc697c Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Tue, 16 May 2023 10:26:26 -0500 Subject: [PATCH 07/40] Updated references --- Dockerfile | 2 ++ reference.md | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 reference.md diff --git a/Dockerfile b/Dockerfile index 3f4bcf4..cd0ee99 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,3 +6,5 @@ WORKDIR /app RUN pip install -r requirements.txt CMD ["python", "-m", "http.server", "8080"] + +# CMD ["gunicorn", "main:app", "--workers", "1", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8080"] \ No newline at end of file diff --git a/reference.md b/reference.md new file mode 100644 index 0000000..08e4e2a --- /dev/null +++ b/reference.md @@ -0,0 +1,34 @@ +```dockerfile +FROM some_image:some_tag + +COPY ./from/local/path /container/dest/path +WORKDIR /container/dest/path + +# install anything +RUN apt-get install -y nginx + +CMD ["what", "command", "to", "run", "by", "default"] +``` + + + +``` +docker build -t tf-python -f Dockerfile . +``` + + +``` +docker run -p 8080:8080 --rm --name my-tf-python tf-python +``` + +``` +docker ps +``` + +``` +docker exec -it my-tf-python /bin/bash +``` + +``` +docker run -e ENV_MESSAGE="hello from the cli" -p 8080:8080 --rm --name my-tf-python tf-python +``` \ No newline at end of file From 3aecb38180e8e89da2ccfa204433c3aac5e4ccf6 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Tue, 16 May 2023 10:43:45 -0500 Subject: [PATCH 08/40] Typo fix --- .github/workflows/container-builld-push.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/container-builld-push.yaml b/.github/workflows/container-builld-push.yaml index a59b10e..549da21 100644 --- a/.github/workflows/container-builld-push.yaml +++ b/.github/workflows/container-builld-push.yaml @@ -24,6 +24,6 @@ jobs: -t jmitchel3/tf-python:latest \ -t jmitchel3/f-python:${GITHUB_SHA::7}-${GITHUB_RUN_ID::5} \ . - - name: Push container - run: | - docker push jmitchel3/tf-python --all-tags + - name: Push container + run: | + docker push jmitchel3/tf-python --all-tags \ No newline at end of file From 6942825fac0e6dc310dcb5e64de91e79edc8bfcf Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Tue, 16 May 2023 11:31:45 -0500 Subject: [PATCH 09/40] Added another environment variable --- src/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.py b/src/main.py index b32a90f..b4ffe04 100644 --- a/src/main.py +++ b/src/main.py @@ -7,6 +7,10 @@ def get_env_message(): return os.environ.get("ENV_MESSAGE") or "Nothing to report" +def get_secret_message(): + return os.environ.get("SECRET_MESSAGE") or "Nothing lurking" + + @app.get("/") def home_view(): - return {"hello": "world", "cron": "smooth-cronjob", "watchtower": "working", "env-message": get_env_message()} + return {"hello": "world", "cron": "smooth-cronjob", "watchtower": "working", "env-message": get_env_message(), "secret-message": get_secret_message()} From 1f44871ad9d3b332a3166c87d400111d35f4f279 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Tue, 16 May 2023 11:33:21 -0500 Subject: [PATCH 10/40] Updated tests for secret message --- src/test_app.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/test_app.py b/src/test_app.py index 0da5d78..b26c025 100644 --- a/src/test_app.py +++ b/src/test_app.py @@ -3,7 +3,7 @@ import pytest # Assuming your FastAPI code is in a file named `main.py` -from .main import app, get_env_message +from .main import app, get_env_message, get_secret_message client = TestClient(app) @@ -16,6 +16,7 @@ def test_home_view(): "cron": "smooth-cronjob", "watchtower": "working", "env-message": get_env_message(), + "secret-message": get_secret_message(), } @pytest.fixture(autouse=True) @@ -29,3 +30,14 @@ def test_env_message_set(monkeypatch): assert response.status_code == 200 assert response.json()["env-message"] == "Test message" + +@pytest.fixture(autouse=True) +def clear_secret_message(monkeypatch): + monkeypatch.delenv("SECRET_MESSAGE", raising=False) + + +def test_secret_message_set(monkeypatch): + monkeypatch.setenv("SECRET_MESSAGE", "Test secret message") + response = client.get("/") + assert response.status_code == 200 + assert response.json()["secret-message"] == "Test secret message" From e7182f319ee09076dd86a95d3917dce1afa00b85 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Tue, 16 May 2023 11:35:45 -0500 Subject: [PATCH 11/40] Updated message set testing --- src/test_app.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/test_app.py b/src/test_app.py index b26c025..e54d7eb 100644 --- a/src/test_app.py +++ b/src/test_app.py @@ -21,23 +21,16 @@ def test_home_view(): @pytest.fixture(autouse=True) def clear_env_message(monkeypatch): + monkeypatch.delenv("SECRET_MESSAGE", raising=False) monkeypatch.delenv("ENV_MESSAGE", raising=False) -def test_env_message_set(monkeypatch): +def test_messages_set(monkeypatch): monkeypatch.setenv("ENV_MESSAGE", "Test message") - response = client.get("/") - assert response.status_code == 200 - assert response.json()["env-message"] == "Test message" - - -@pytest.fixture(autouse=True) -def clear_secret_message(monkeypatch): - monkeypatch.delenv("SECRET_MESSAGE", raising=False) - - -def test_secret_message_set(monkeypatch): monkeypatch.setenv("SECRET_MESSAGE", "Test secret message") response = client.get("/") assert response.status_code == 200 - assert response.json()["secret-message"] == "Test secret message" + data = response.json() + assert data["env-message"] == "Test message" + assert data["secret-message"] == "Test secret message" + From e63fb60bfa3fa6aa6079e7c139acbf9b95480223 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Tue, 16 May 2023 11:38:31 -0500 Subject: [PATCH 12/40] Updated gunicorn test for new env var --- src/test_gunicorn.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test_gunicorn.py b/src/test_gunicorn.py index 1788a4c..4788168 100644 --- a/src/test_gunicorn.py +++ b/src/test_gunicorn.py @@ -18,6 +18,7 @@ def test_gunicorn_start(): "cron": "smooth-cronjob", "watchtower": "working", "env-message": os.environ.get("ENV_MESSAGE") or "Nothing to report", + "secret-message": os.environ.get("SECRET_MESSAGE") or "Nothing lurking" } finally: gunicorn_process.terminate() From b7fd1447aabf1f4e6fc07352c13a769f87085269 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Tue, 16 May 2023 11:40:58 -0500 Subject: [PATCH 13/40] Updated Dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index cd0ee99..8619119 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,6 @@ WORKDIR /app RUN pip install -r requirements.txt -CMD ["python", "-m", "http.server", "8080"] +# CMD ["python", "-m", "http.server", "8080"] -# CMD ["gunicorn", "main:app", "--workers", "1", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8080"] \ No newline at end of file +CMD ["gunicorn", "main:app", "--workers", "1", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8080"] \ No newline at end of file From eff5329112932dcbe3fd98a269403cfac493af11 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Tue, 16 May 2023 11:43:08 -0500 Subject: [PATCH 14/40] Updated deployment manifest --- ops/tf-python-manifest.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ops/tf-python-manifest.yaml b/ops/tf-python-manifest.yaml index 1467965..0e0e2ba 100644 --- a/ops/tf-python-manifest.yaml +++ b/ops/tf-python-manifest.yaml @@ -22,6 +22,8 @@ spec: value: "8080" - name: ENV_MESSAGE value: "Hello from Kubernetes" + - name: SECRET_MESSAGE + value: "This isn't really secret" --- apiVersion: v1 From daac6a25b95732dc639945fea92a1578428bccec Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Tue, 16 May 2023 11:43:54 -0500 Subject: [PATCH 15/40] Updated dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8619119..cd0ee99 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,6 @@ WORKDIR /app RUN pip install -r requirements.txt -# CMD ["python", "-m", "http.server", "8080"] +CMD ["python", "-m", "http.server", "8080"] -CMD ["gunicorn", "main:app", "--workers", "1", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8080"] \ No newline at end of file +# CMD ["gunicorn", "main:app", "--workers", "1", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8080"] \ No newline at end of file From 27e84d78d7f9d8382693dd42d7f22d993d99504c Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 17 May 2023 10:27:01 -0500 Subject: [PATCH 16/40] Added tf module --- infra/main.tf | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 infra/main.tf diff --git a/infra/main.tf b/infra/main.tf new file mode 100644 index 0000000..e142764 --- /dev/null +++ b/infra/main.tf @@ -0,0 +1,30 @@ +terraform { + required_version = ">= 0.15" + required_providers { + linode = { + source = "linode/linode" + version = "1.30.0" + } + } + backend "s3" {} # object storage +} + +provider "linode" { + token = var.linode_api_token +} + +variable "linode_api_token" { + description = "Your Linode API Personal Access Token. (required)" + sensitive = true +} + +resource "linode_lke_cluster" "terraform_k8s" { + k8s_version="1.26" + label="tf-k8s" + region="us-east" + tags=["tf-k8s"] + pool { + type = "g6-standard-1" + count = 3 + } +} \ No newline at end of file From 953ff48e3ed12e8dabbe68ac7a83ebe92c387c70 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 17 May 2023 10:40:26 -0500 Subject: [PATCH 17/40] Added terrafrom workflow --- .github/workflows/infra-sync.yaml | 51 +++++++++++++++++++++++++++++++ .gitignore | 4 +++ 2 files changed, 55 insertions(+) create mode 100644 .github/workflows/infra-sync.yaml diff --git a/.github/workflows/infra-sync.yaml b/.github/workflows/infra-sync.yaml new file mode 100644 index 0000000..73b940f --- /dev/null +++ b/.github/workflows/infra-sync.yaml @@ -0,0 +1,51 @@ +name: Sync Infrastructure via Terraform +on: + workflow_dispatch: + # push: + # branches: + # - main + # paths: + # - 'infra/**' + # - 'config/**' + # - '.github/workflows/infra-sync.yaml' + +jobs: + terraform: + name: Apply Terraform + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + # setup terraform + # Terraform Backend -> s3 bucket + # Terraform TFVars -> pat + # init terraform + # validate + # auto-apply + - name: Setup Terraform + uses: hashicorp/setup-terraform@v2 + with: + terraform_version: 1.4.6 + - name: Add Terraform Backend for S3 + run: | + cat << EOF > infra/backend + skip_credentials_validation=true + skip_region_validation=true + bucket="${{ secrets.LINODE_OBJECT_STORAGE_BUCKET }}" + key="tf-k8s.tfstate" + region="us-east-1" + endpoint="us-east-1.linodeobjects.com" + access_key="${{ secrets.LINODE_OBJECT_STORAGE_ACCESS_KEY }}" + secret_key="${{ secrets.LINODE_OBJECT_STORAGE_SECRET_KEY }}" + EOF + - name: Add Terraform TFVars + run: | + cat << EOF > infra/terraform.tfvars + linode_api_token="${{ secrets.LINODE_PA_TOKEN }}" + EOF + - name: Terraform Init + run: terraform -chdir=./infra init -backend-config=backend + - name: Terraform Validate + run: terraform -chdir=./infra validate -no-color + - name: Terraform Apply Changes + run: terraform -chdir=./infra apply -auto-approve \ No newline at end of file diff --git a/.gitignore b/.gitignore index 68bc17f..b517d74 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +infra/backend +infra/terraform.tfvars + + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] From c102c96b130f0bf317ce64c943652839e43a53eb Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 17 May 2023 11:07:16 -0500 Subject: [PATCH 18/40] Updated dockerfile cmd --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index cd0ee99..8619119 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,6 @@ WORKDIR /app RUN pip install -r requirements.txt -CMD ["python", "-m", "http.server", "8080"] +# CMD ["python", "-m", "http.server", "8080"] -# CMD ["gunicorn", "main:app", "--workers", "1", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8080"] \ No newline at end of file +CMD ["gunicorn", "main:app", "--workers", "1", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8080"] \ No newline at end of file From 5451625aa6703e059052912487553124d7a1301f Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 17 May 2023 11:11:27 -0500 Subject: [PATCH 19/40] Updated workflow tag --- .github/workflows/container-builld-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/container-builld-push.yaml b/.github/workflows/container-builld-push.yaml index 549da21..80f034c 100644 --- a/.github/workflows/container-builld-push.yaml +++ b/.github/workflows/container-builld-push.yaml @@ -22,7 +22,7 @@ jobs: run: | docker build -f Dockerfile \ -t jmitchel3/tf-python:latest \ - -t jmitchel3/f-python:${GITHUB_SHA::7}-${GITHUB_RUN_ID::5} \ + -t jmitchel3/tf-python:${GITHUB_SHA::7}-${GITHUB_RUN_ID::5} \ . - name: Push container run: | From 4c3d250f58fe9ffcc76c6b337e88fa5fe8800cf1 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 17 May 2023 11:15:33 -0500 Subject: [PATCH 20/40] Added rollout to deployment --- .github/workflows/k8s-apply.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/k8s-apply.yaml b/.github/workflows/k8s-apply.yaml index 2479dac..78b4979 100644 --- a/.github/workflows/k8s-apply.yaml +++ b/.github/workflows/k8s-apply.yaml @@ -20,6 +20,9 @@ jobs: - name: Apply Kubernetes Config run: | KUBECONFIG=~/.kube/kubeconfig.yaml kubectl apply -f ops/ + - name: Rollout tf-python + run: | + KUBECONFIG=~/.kube/kubeconfig.yaml kubectl rollout restart deployment/tf-python - name: Echo deployments run: | KUBECONFIG=~/.kube/kubeconfig.yaml kubectl get deployments From f09a0c0c6cc281746423f95156e600b334567658 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 17 May 2023 11:17:49 -0500 Subject: [PATCH 21/40] updated manifest --- ops/tf-python-manifest.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ops/tf-python-manifest.yaml b/ops/tf-python-manifest.yaml index 0e0e2ba..98c86b2 100644 --- a/ops/tf-python-manifest.yaml +++ b/ops/tf-python-manifest.yaml @@ -23,7 +23,7 @@ spec: - name: ENV_MESSAGE value: "Hello from Kubernetes" - name: SECRET_MESSAGE - value: "This isn't really secret" + value: "Secret" --- apiVersion: v1 From fd266db508e20b89204cc7e28ad2f39cc42f1c70 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 17 May 2023 11:26:23 -0500 Subject: [PATCH 22/40] Updated tf-python manifests with conigmap --- ops/1-tf-configmap.yaml | 7 +++++++ ...hon-manifest.yaml => 2-tf-deployment.yaml} | 19 +++++-------------- ops/3-tf-service.yaml | 12 ++++++++++++ 3 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 ops/1-tf-configmap.yaml rename ops/{tf-python-manifest.yaml => 2-tf-deployment.yaml} (69%) create mode 100644 ops/3-tf-service.yaml diff --git a/ops/1-tf-configmap.yaml b/ops/1-tf-configmap.yaml new file mode 100644 index 0000000..0b3fe28 --- /dev/null +++ b/ops/1-tf-configmap.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: tf-python-cm +data: + ENV_MESSAGE: This is a configmap! + MG: abc \ No newline at end of file diff --git a/ops/tf-python-manifest.yaml b/ops/2-tf-deployment.yaml similarity index 69% rename from ops/tf-python-manifest.yaml rename to ops/2-tf-deployment.yaml index 98c86b2..e53a0d9 100644 --- a/ops/tf-python-manifest.yaml +++ b/ops/2-tf-deployment.yaml @@ -21,20 +21,11 @@ spec: - name: PORT value: "8080" - name: ENV_MESSAGE - value: "Hello from Kubernetes" + valueFrom: + configMapRef: + name: tf-python-cm + key: ENV_MESSAGE - name: SECRET_MESSAGE value: "Secret" ---- -apiVersion: v1 -kind: Service -metadata: - name: tf-python -spec: - type: LoadBalancer - ports: - - port: 80 - targetPort: 8080 - protocol: TCP - selector: - app: tf-python + diff --git a/ops/3-tf-service.yaml b/ops/3-tf-service.yaml new file mode 100644 index 0000000..e739db7 --- /dev/null +++ b/ops/3-tf-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: tf-python +spec: + type: LoadBalancer + ports: + - port: 80 + targetPort: 8080 + protocol: TCP + selector: + app: tf-python \ No newline at end of file From a4612e4249bd4fb38803b6ca83222d00c0a267f4 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 17 May 2023 11:28:06 -0500 Subject: [PATCH 23/40] ConfigMapKeyRef value --- ops/2-tf-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ops/2-tf-deployment.yaml b/ops/2-tf-deployment.yaml index e53a0d9..cc066e2 100644 --- a/ops/2-tf-deployment.yaml +++ b/ops/2-tf-deployment.yaml @@ -22,7 +22,7 @@ spec: value: "8080" - name: ENV_MESSAGE valueFrom: - configMapRef: + configMapKeyRef: name: tf-python-cm key: ENV_MESSAGE - name: SECRET_MESSAGE From 71eabfd9d310c0c49b26d16d90e0989d36326da1 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 17 May 2023 11:32:54 -0500 Subject: [PATCH 24/40] Updated for secrets --- ops/0-tf-secret.yaml | 6 ++++++ ops/2-tf-deployment.yaml | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 ops/0-tf-secret.yaml diff --git a/ops/0-tf-secret.yaml b/ops/0-tf-secret.yaml new file mode 100644 index 0000000..c3b4c46 --- /dev/null +++ b/ops/0-tf-secret.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Secret +metadata: + name: tf-python-secret +stringData: + SECRET_MESSAGE: Not a good secret \ No newline at end of file diff --git a/ops/2-tf-deployment.yaml b/ops/2-tf-deployment.yaml index cc066e2..857a4c3 100644 --- a/ops/2-tf-deployment.yaml +++ b/ops/2-tf-deployment.yaml @@ -20,12 +20,19 @@ spec: env: - name: PORT value: "8080" - - name: ENV_MESSAGE - valueFrom: - configMapKeyRef: - name: tf-python-cm - key: ENV_MESSAGE + # - name: ENV_MESSAGE + # valueFrom: + # configMapKeyRef: + # name: tf-python-cm + # key: ENV_MESSAGE - name: SECRET_MESSAGE - value: "Secret" + valueFrom: + secretKeyRef: + name: tf-python-secret + key: SECRET_MESSAGE + envFrom: + - configMapKeyRef: + name: tf-python-cm + From 619c5b6074bf0ac3d3b2d30bcf2debb91b009b5d Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 17 May 2023 11:34:37 -0500 Subject: [PATCH 25/40] updated config map --- ops/2-tf-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ops/2-tf-deployment.yaml b/ops/2-tf-deployment.yaml index 857a4c3..6a502a0 100644 --- a/ops/2-tf-deployment.yaml +++ b/ops/2-tf-deployment.yaml @@ -31,7 +31,7 @@ spec: name: tf-python-secret key: SECRET_MESSAGE envFrom: - - configMapKeyRef: + - configMapRef: name: tf-python-cm From 91be672ba6b1417bfab981b62df183ba18ceec9c Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 17 May 2023 11:36:12 -0500 Subject: [PATCH 26/40] Updated code --- ops/2-tf-deployment.yaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ops/2-tf-deployment.yaml b/ops/2-tf-deployment.yaml index 6a502a0..1f7c27a 100644 --- a/ops/2-tf-deployment.yaml +++ b/ops/2-tf-deployment.yaml @@ -20,19 +20,19 @@ spec: env: - name: PORT value: "8080" - # - name: ENV_MESSAGE - # valueFrom: - # configMapKeyRef: - # name: tf-python-cm - # key: ENV_MESSAGE + - name: ENV_MESSAGE + valueFrom: + configMapKeyRef: + name: tf-python-cm + key: ENV_MESSAGE - name: SECRET_MESSAGE valueFrom: secretKeyRef: name: tf-python-secret key: SECRET_MESSAGE - envFrom: - - configMapRef: - name: tf-python-cm + # envFrom: + # - configMapRef: + # name: tf-python-cm From d957c4e5bd8800a61bebfb343220670149300ac0 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 17 May 2023 11:39:35 -0500 Subject: [PATCH 27/40] Update k8s-apply --- .github/workflows/k8s-apply.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/k8s-apply.yaml b/.github/workflows/k8s-apply.yaml index 78b4979..5b25326 100644 --- a/.github/workflows/k8s-apply.yaml +++ b/.github/workflows/k8s-apply.yaml @@ -17,6 +17,16 @@ jobs: cat << EOF >> ~/.kube/kubeconfig.yaml ${{ secrets.KUBECONFIG }} EOF + - name: Add Secret + run: | + cat << EOF >> ops/0-tf-secret.yaml + apiVersion: v1 + kind: Secret + metadata: + name: tf-python-secret + stringData: + SECRET_MESSAGE: ${{ secrets.ENV_SECRET_MESSAGE }} + EOF - name: Apply Kubernetes Config run: | KUBECONFIG=~/.kube/kubeconfig.yaml kubectl apply -f ops/ From d97c0c5fd0355713302f9727e9cc99587e9f3b46 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 17 May 2023 11:41:12 -0500 Subject: [PATCH 28/40] Update k8s-apply --- .github/workflows/k8s-apply.yaml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/k8s-apply.yaml b/.github/workflows/k8s-apply.yaml index 5b25326..a93a567 100644 --- a/.github/workflows/k8s-apply.yaml +++ b/.github/workflows/k8s-apply.yaml @@ -17,16 +17,16 @@ jobs: cat << EOF >> ~/.kube/kubeconfig.yaml ${{ secrets.KUBECONFIG }} EOF - - name: Add Secret - run: | - cat << EOF >> ops/0-tf-secret.yaml - apiVersion: v1 - kind: Secret - metadata: - name: tf-python-secret - stringData: - SECRET_MESSAGE: ${{ secrets.ENV_SECRET_MESSAGE }} - EOF + # - name: Add Secret + # run: | + # cat << EOF >> ops/0-tf-secret.yaml + # apiVersion: v1 + # kind: Secret + # metadata: + # name: tf-python-secret + # stringData: + # SECRET_MESSAGE: ${{ secrets.ENV_SECRET_MESSAGE }} + # EOF - name: Apply Kubernetes Config run: | KUBECONFIG=~/.kube/kubeconfig.yaml kubectl apply -f ops/ From b66a3250de52728b72f8478d1def782956dca798 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 17 May 2023 11:55:14 -0500 Subject: [PATCH 29/40] Mass changes --- .github/workflows/infra-destroy.yaml | 51 ++++++++++++++++++++++++++++ .gitignore | 2 +- ops/3-tf-service.yaml | 5 +-- ops/4-tf-ingress.yaml | 31 +++++++++++++++++ 4 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/infra-destroy.yaml create mode 100644 ops/4-tf-ingress.yaml diff --git a/.github/workflows/infra-destroy.yaml b/.github/workflows/infra-destroy.yaml new file mode 100644 index 0000000..34aa01b --- /dev/null +++ b/.github/workflows/infra-destroy.yaml @@ -0,0 +1,51 @@ +name: Destory Infrastructure via Terraform +on: + workflow_dispatch: + # push: + # branches: + # - main + # paths: + # - 'infra/**' + # - 'config/**' + # - '.github/workflows/infra-sync.yaml' + +jobs: + terraform: + name: Apply Terraform + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + # setup terraform + # Terraform Backend -> s3 bucket + # Terraform TFVars -> pat + # init terraform + # validate + # auto-apply + - name: Setup Terraform + uses: hashicorp/setup-terraform@v2 + with: + terraform_version: 1.4.6 + - name: Add Terraform Backend for S3 + run: | + cat << EOF > infra/backend + skip_credentials_validation=true + skip_region_validation=true + bucket="${{ secrets.LINODE_OBJECT_STORAGE_BUCKET }}" + key="tf-k8s.tfstate" + region="us-east-1" + endpoint="us-east-1.linodeobjects.com" + access_key="${{ secrets.LINODE_OBJECT_STORAGE_ACCESS_KEY }}" + secret_key="${{ secrets.LINODE_OBJECT_STORAGE_SECRET_KEY }}" + EOF + - name: Add Terraform TFVars + run: | + cat << EOF > infra/terraform.tfvars + linode_api_token="${{ secrets.LINODE_PA_TOKEN }}" + EOF + - name: Terraform Init + run: terraform -chdir=./infra init -backend-config=backend + - name: Terraform Validate + run: terraform -chdir=./infra validate -no-color + - name: Terraform Apply Changes + run: terraform -chdir=./infra apply -auto-approve -destroy \ No newline at end of file diff --git a/.gitignore b/.gitignore index b517d74..df8b7e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ infra/backend infra/terraform.tfvars - +.kube/ # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/ops/3-tf-service.yaml b/ops/3-tf-service.yaml index e739db7..921a2f9 100644 --- a/ops/3-tf-service.yaml +++ b/ops/3-tf-service.yaml @@ -3,9 +3,10 @@ kind: Service metadata: name: tf-python spec: - type: LoadBalancer + type: ClusterIP # delete my nodebalancer from Linode ports: - - port: 80 + - name: http + port: 80 targetPort: 8080 protocol: TCP selector: diff --git a/ops/4-tf-ingress.yaml b/ops/4-tf-ingress.yaml new file mode 100644 index 0000000..b7c2be6 --- /dev/null +++ b/ops/4-tf-ingress.yaml @@ -0,0 +1,31 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: tf-ingress + annotations: + kubernetes.io/ingress.class: nginx + # cert-manager.io/cluster-issuer: "letsencrypt" + # nginx.ingress.kubernetes.io/force-ssl-redirect: "true" + # nginx.ingress.kubernetes.io/ssl-passthrough: "true" +spec: + rules: + - host: www.pythonkeras.com + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: tf-python + port: + name: http + - host: pythonkeras.com + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: tf-python + port: + name: http From 855a88f2ab26649aedf17bd37ff8f5a3c18879db Mon Sep 17 00:00:00 2001 From: Coding For Entrepreneurs Date: Fri, 19 May 2023 10:12:50 -0500 Subject: [PATCH 30/40] Update k8s-apply.yaml for json-based secret --- .github/workflows/k8s-apply.yaml | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/k8s-apply.yaml b/.github/workflows/k8s-apply.yaml index a93a567..160b86e 100644 --- a/.github/workflows/k8s-apply.yaml +++ b/.github/workflows/k8s-apply.yaml @@ -17,16 +17,23 @@ jobs: cat << EOF >> ~/.kube/kubeconfig.yaml ${{ secrets.KUBECONFIG }} EOF - # - name: Add Secret - # run: | - # cat << EOF >> ops/0-tf-secret.yaml - # apiVersion: v1 - # kind: Secret - # metadata: - # name: tf-python-secret - # stringData: - # SECRET_MESSAGE: ${{ secrets.ENV_SECRET_MESSAGE }} - # EOF + - name: Add Secret + run: | + if [ -f ops/0-tf-secret.yaml ]; then + rm ops/0-tf-secret.yaml + fi + cat << EOF >> ops/0-tf-secret.json + { + "apiVersion": v1, + "kind": "Secret", + "metadata": { + "name": "tf-python-secret" + }, + "stringData": { + "SECRET_MESSAGE": "${{ secrets.ENV_SECRET_MESSAGE }}" + } + } + EOF - name: Apply Kubernetes Config run: | KUBECONFIG=~/.kube/kubeconfig.yaml kubectl apply -f ops/ From 71806bd8da10f43490839770620362e0935ec526 Mon Sep 17 00:00:00 2001 From: Coding For Entrepreneurs Date: Fri, 19 May 2023 10:14:26 -0500 Subject: [PATCH 31/40] Update k8s-apply.yaml --- .github/workflows/k8s-apply.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/k8s-apply.yaml b/.github/workflows/k8s-apply.yaml index 160b86e..57e5584 100644 --- a/.github/workflows/k8s-apply.yaml +++ b/.github/workflows/k8s-apply.yaml @@ -24,7 +24,7 @@ jobs: fi cat << EOF >> ops/0-tf-secret.json { - "apiVersion": v1, + "apiVersion": "v1", "kind": "Secret", "metadata": { "name": "tf-python-secret" From d5d3b5281061a14de2db002da2468971d0d0c346 Mon Sep 17 00:00:00 2001 From: Coding For Entrepreneurs Date: Fri, 19 May 2023 10:17:58 -0500 Subject: [PATCH 32/40] Fixed typo --- .github/workflows/infra-destroy.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/infra-destroy.yaml b/.github/workflows/infra-destroy.yaml index 34aa01b..aa9a131 100644 --- a/.github/workflows/infra-destroy.yaml +++ b/.github/workflows/infra-destroy.yaml @@ -1,4 +1,4 @@ -name: Destory Infrastructure via Terraform +name: Destroy Infrastructure via Terraform on: workflow_dispatch: # push: @@ -48,4 +48,4 @@ jobs: - name: Terraform Validate run: terraform -chdir=./infra validate -no-color - name: Terraform Apply Changes - run: terraform -chdir=./infra apply -auto-approve -destroy \ No newline at end of file + run: terraform -chdir=./infra apply -auto-approve -destroy From d8fb6aca4bcb33dce81a6f54a031178b8ddce6fe Mon Sep 17 00:00:00 2001 From: Coding For Entrepreneurs Date: Fri, 19 May 2023 10:18:31 -0500 Subject: [PATCH 33/40] Renamed Workflow --- .github/workflows/py-rnd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/py-rnd.yml b/.github/workflows/py-rnd.yml index 7937750..a681a1f 100644 --- a/.github/workflows/py-rnd.yml +++ b/.github/workflows/py-rnd.yml @@ -1,7 +1,7 @@ # This workflow will install Python dependencies # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python -name: Python application +name: Test Python Application on: workflow_dispatch: From b3fab17633c2bc382a101690ae013c23767ad9ea Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 24 May 2023 09:16:17 -0500 Subject: [PATCH 34/40] Using latest terraform version --- infra/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/main.tf b/infra/main.tf index e142764..7457c4a 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -3,7 +3,7 @@ terraform { required_providers { linode = { source = "linode/linode" - version = "1.30.0" + # version = "1.30.0" } } backend "s3" {} # object storage From 9e06075b58734682ed3d808bb9586269107becbc Mon Sep 17 00:00:00 2001 From: Coding For Entrepreneurs Date: Wed, 7 Jun 2023 11:43:19 -0500 Subject: [PATCH 35/40] Create 6-tf-redis.yaml --- ops/6-tf-redis.yaml | 64 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 ops/6-tf-redis.yaml diff --git a/ops/6-tf-redis.yaml b/ops/6-tf-redis.yaml new file mode 100644 index 0000000..7c22e13 --- /dev/null +++ b/ops/6-tf-redis.yaml @@ -0,0 +1,64 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: redis-statefulset + labels: + app: redis-statefulset +spec: + replicas: 1 + # serviceName: redis-service + selector: + matchLabels: + app: redis-statefulset + template: + metadata: + labels: + app: redis-statefulset + spec: + containers: + - name: redis-container + image: redis:latest + imagePullPolicy: IfNotPresent + command: + - redis-server + ports: + - name: redis-port + containerPort: 6379 + volumeMounts: + - name: redis-data + mountPath: /data + initContainers: + - name: delete-existing-data + image: alpine:latest + command: ["sh", "-c", "rm -rf /mnt/*"] + volumeMounts: + - name: redis-data + mountPath: /mnt + volumeClaimTemplates: + - metadata: + name: redis-data + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 100Gi + storageClassName: linode-block-storage + +--- +apiVersion: v1 +kind: Service +metadata: + name: redis-db + labels: + app: redis-db +spec: + type: ClusterIP # + ports: + - protocol: TCP + port: 6379 + targetPort: redis-port + selector: + app: redis-statefulset + +# redis://redis-db.default.svc.cluster.local:6379 From 6101212b396ccbc4a1d7c6e3b3cb1a647546ce15 Mon Sep 17 00:00:00 2001 From: Coding For Entrepreneurs Date: Wed, 7 Jun 2023 11:43:48 -0500 Subject: [PATCH 36/40] Create 5-tf-statefulset.yaml --- ops/5-tf-statefulset.yaml | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 ops/5-tf-statefulset.yaml diff --git a/ops/5-tf-statefulset.yaml b/ops/5-tf-statefulset.yaml new file mode 100644 index 0000000..abb6b94 --- /dev/null +++ b/ops/5-tf-statefulset.yaml @@ -0,0 +1,52 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: tf-python +spec: + replicas: 1 + selector: + matchLabels: + app: tf-python + template: + metadata: + labels: + app: tf-python + spec: + containers: + - name: tf-python + image: jmitchel3/tf-python:latest + ports: + - containerPort: 8080 + env: + - name: PORT + value: "8080" + - name: ENV_MESSAGE + valueFrom: + configMapKeyRef: + name: tf-python-cm + key: ENV_MESSAGE + - name: SECRET_MESSAGE + valueFrom: + secretKeyRef: + name: tf-python-secret + key: SECRET_MESSAGE + volumeMounts: + - name: tf-volume + mountPath: /data + # initContainers: + # - name: delete-existing-data + # image: alpine:latest + # command: ["sh", "-c", "rm -rf /mnt/*"] + # volumeMounts: + # - name: tf-volume + # mountPath: /mnt + volumeClaimTemplates: + - metadata: + name: tf-volume + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 10Gi + storageClassName: linode-block-storage From 762976b6acc62967a8604317eb08d7387370eec4 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Sat, 10 Jun 2023 13:07:34 -0500 Subject: [PATCH 37/40] Added vs-code workspace file --- tf.code-workspace | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tf.code-workspace diff --git a/tf.code-workspace b/tf.code-workspace new file mode 100644 index 0000000..a0dbf82 --- /dev/null +++ b/tf.code-workspace @@ -0,0 +1,20 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "files.autoSave": "afterDelay", + "terminal.integrated.env.osx": { + "KUBECONFIG": "${workspaceFolder}/.kube/kubeconfig.yaml", + "KUBE_EDITOR": "nano", + }, + "terminal.integrated.env.windows": { + "KUBECONFIG": "${workspaceFolder}\\.kube\\kubeconfig.yaml" + }, + "terminal.integrated.env.linux": { + "KUBECONFIG": "${workspaceFolder}/.kube/kubeconfig.yaml" + }, + } +} \ No newline at end of file From 49ece758301de8d5785cb6b9dbeaba2944d043da Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Sat, 10 Jun 2023 13:24:01 -0500 Subject: [PATCH 38/40] Updated lke node size --- infra/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/main.tf b/infra/main.tf index 7457c4a..8eb2238 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -24,7 +24,7 @@ resource "linode_lke_cluster" "terraform_k8s" { region="us-east" tags=["tf-k8s"] pool { - type = "g6-standard-1" + type = "g6-standard-2" count = 3 } } \ No newline at end of file From 4deb76923e447604945efbb377dd1adab2d8f934 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Sat, 10 Jun 2023 13:51:56 -0500 Subject: [PATCH 39/40] Added additional compute for knative --- infra/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/main.tf b/infra/main.tf index 8eb2238..2dbafd9 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -24,7 +24,7 @@ resource "linode_lke_cluster" "terraform_k8s" { region="us-east" tags=["tf-k8s"] pool { - type = "g6-standard-2" + type = "g6-standard-4" count = 3 } } \ No newline at end of file From a306c674f35e064fa69fd75ef50a1b67ffa408b8 Mon Sep 17 00:00:00 2001 From: CodingForEntrepreneurs Date: Wed, 14 Jun 2023 12:56:14 -0500 Subject: [PATCH 40/40] Finished for session 4 --- ops/2-tf-deployment.yaml | 4 +++ ops/7-tf-knative-service.yaml | 46 ++++++++++++++++++++++++++++ ops/8-tf-knative-service-demo.yaml | 18 +++++++++++ ops/9-tf-knative-virtualservice.yaml | 25 +++++++++++++++ scripts/install-knative.sh | 22 +++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 ops/7-tf-knative-service.yaml create mode 100644 ops/8-tf-knative-service-demo.yaml create mode 100644 ops/9-tf-knative-virtualservice.yaml create mode 100755 scripts/install-knative.sh diff --git a/ops/2-tf-deployment.yaml b/ops/2-tf-deployment.yaml index 1f7c27a..7e210c4 100644 --- a/ops/2-tf-deployment.yaml +++ b/ops/2-tf-deployment.yaml @@ -20,6 +20,10 @@ spec: env: - name: PORT value: "8080" + - name: VERSION + value: "1.0.0" + - name: KNATIVE_URL + value: "http://tf-python.apps.svc.cluster.local" - name: ENV_MESSAGE valueFrom: configMapKeyRef: diff --git a/ops/7-tf-knative-service.yaml b/ops/7-tf-knative-service.yaml new file mode 100644 index 0000000..902a3dd --- /dev/null +++ b/ops/7-tf-knative-service.yaml @@ -0,0 +1,46 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: apps +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: tf-python-cm + namespace: apps +data: + ENV_MESSAGE: This is a configmap! + MG: abc + NEW_ONE: abc + +--- +apiVersion: serving.knative.dev/v1 +kind: Service +metadata: + name: tf-python + namespace: apps # tf-python.apps.svc.cluster.local +spec: + template: + spec: + containers: + - name: tf-py-container + image: jmitchel3/tf-python:latest + ports: + - containerPort: 8080 + env: + - name: VERSION + value: "1.0.1" + - name: ENV_MESSAGE + valueFrom: + configMapKeyRef: + name: tf-python-cm + key: ENV_MESSAGE + # securityContext: + # allowPrivilegeEscalation: false + # runAsNonRoot: false + # capabilities: + # drop: + # - ALL + # seccompProfile: + # type: RuntimeDefault + diff --git a/ops/8-tf-knative-service-demo.yaml b/ops/8-tf-knative-service-demo.yaml new file mode 100644 index 0000000..d68f8d5 --- /dev/null +++ b/ops/8-tf-knative-service-demo.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: demo +--- +apiVersion: serving.knative.dev/v1 +kind: Service +metadata: + name: tf-python + namespace: demo # tf-python.demo.svc.cluster.local # tf-python.demo.pythonkeras.com +spec: + template: + spec: + containers: + - name: cfe-nginx-c + image: codingforentrepreneurs/cfe-nginx:latest + ports: + - containerPort: 80 \ No newline at end of file diff --git a/ops/9-tf-knative-virtualservice.yaml b/ops/9-tf-knative-virtualservice.yaml new file mode 100644 index 0000000..79945aa --- /dev/null +++ b/ops/9-tf-knative-virtualservice.yaml @@ -0,0 +1,25 @@ +apiVersion: networking.istio.io/v1alpha3 +kind: VirtualService +metadata: + name: tf-python-root + namespace: apps +spec: + gateways: + - knative-shared-gateway.knative-serving.svc.cluster.local + - knative-serving/knative-ingress-gateway + hosts: + - pythonkeras.com + - www.pythonkeras.com + http: + - name: http-route + match: + - uri: + prefix: "/" # http://tf-python.apps.pythonkeras.com/ + rewrite: + authority: tf-python.apps.pythonkeras.com + route: + - destination: + host: tf-python.apps.svc.cluster.local + port: + number: 80 + weight: 100 \ No newline at end of file diff --git a/scripts/install-knative.sh b/scripts/install-knative.sh new file mode 100755 index 0000000..b73bdd0 --- /dev/null +++ b/scripts/install-knative.sh @@ -0,0 +1,22 @@ +# Get version at https://knative.dev/docs/install/yaml-install/serving/install-serving-with-yaml/ +# +export KNATIVE_VERSION="v1.10.1" # ensure ISTIO install matches this version too + +# Install knative serving +# Ref: https://knative.dev/docs/install/yaml-install/serving/install-serving-with-yaml/#install-the-knative-serving-component +kubectl apply -f https://github.com/knative/serving/releases/download/knative-$KNATIVE_VERSION/serving-crds.yaml +kubectl apply -f https://github.com/knative/serving/releases/download/knative-$KNATIVE_VERSION/serving-core.yaml + + +# install istio +# Ref: https://knative.dev/docs/install/yaml-install/serving/install-serving-with-yaml/#install-a-networking-layer +kubectl apply -l knative.dev/crd-install=true -f https://github.com/knative/net-istio/releases/download/knative-$KNATIVE_VERSION/istio.yaml +kubectl apply -f https://github.com/knative/net-istio/releases/download/knative-$KNATIVE_VERSION/istio.yaml +kubectl apply -f https://github.com/knative/net-istio/releases/download/knative-$KNATIVE_VERSION/net-istio.yaml + +# Confirm installed: +kubectl --namespace istio-system get service istio-ingressgateway +export KNATIVE_INGRESS_IP=$(kubectl --namespace istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + +echo "Your IP Address is: $KNATIVE_INGRESS_IP" +echo "Add a cname record for your domain using the above IP address." \ No newline at end of file