From 4047993536e409b0ceeafbc31f4695f9071d80b2 Mon Sep 17 00:00:00 2001 From: Greg Kostin Date: Tue, 25 May 2021 00:20:13 -0400 Subject: [PATCH] fulcimen-demo --- .../fulcimen-load-balancer-service.yaml | 13 ++++ .../manifests/fulcimen-rails-deployment.yaml | 21 +++++++ .github/workflows/delete-workflow-runs.yaml | 19 ++++++ ...ml => deploy-branch-image-to-testing.yaml} | 8 +-- .../deploy-web-nginx-to-testing.yaml | 37 +++++++++++ .../workflows/echo-env-context-to-json.yaml | 5 ++ .github/workflows/package-nginx-image.yaml | 23 +++++++ Dockerfile | 62 +++++++++++++++++++ Dockerfile.noah | 58 +++++++++++++++++ k8s/fulcimen-demo/apply.sh | 7 +++ k8s/fulcimen-demo/delete.sh | 7 +++ .../fulcimen-demo-namespace.yaml | 4 ++ .../fulcimen-demo-resource-quota.yaml | 11 ++++ k8s/fulcimen-demo/fulcimen-deployment.yaml | 34 ++++++++++ .../fulcimen-node-port-service.yaml | 16 +++++ .../mysql-client-alpine-pod.yaml | 51 +++++++++++++++ .../mysql-external-name-service.yaml | 17 +++++ k8s/fulcimen-staging/mysql-ep.yaml | 12 ++++ k8s/nginx-demo/apply.sh | 5 ++ k8s/nginx-demo/delete.sh | 5 ++ k8s/nginx-demo/nginx-demo-namespace.yaml | 4 ++ k8s/nginx-demo/nginx-demo-resource-quota.yaml | 11 ++++ k8s/nginx-demo/nginx-deployment.yaml | 31 ++++++++++ k8s/nginx-demo/nginx-node-port-service.yaml | 16 +++++ k8s/web/node-port.yaml | 15 +++++ nginx/Dockerfile.nginx | 2 + nginx/index.html | 9 +++ 27 files changed, 499 insertions(+), 4 deletions(-) create mode 100644 .github/manifests/fulcimen-load-balancer-service.yaml create mode 100644 .github/manifests/fulcimen-rails-deployment.yaml create mode 100644 .github/workflows/delete-workflow-runs.yaml rename .github/workflows/{deploy-branch-to-testing.yaml => deploy-branch-image-to-testing.yaml} (86%) create mode 100644 .github/workflows/deploy-web-nginx-to-testing.yaml create mode 100644 .github/workflows/package-nginx-image.yaml create mode 100644 Dockerfile create mode 100644 Dockerfile.noah create mode 100755 k8s/fulcimen-demo/apply.sh create mode 100755 k8s/fulcimen-demo/delete.sh create mode 100644 k8s/fulcimen-demo/fulcimen-demo-namespace.yaml create mode 100644 k8s/fulcimen-demo/fulcimen-demo-resource-quota.yaml create mode 100644 k8s/fulcimen-demo/fulcimen-deployment.yaml create mode 100644 k8s/fulcimen-demo/fulcimen-node-port-service.yaml create mode 100644 k8s/fulcimen-demo/mysql-client-alpine-pod.yaml create mode 100644 k8s/fulcimen-demo/mysql-external-name-service.yaml create mode 100644 k8s/fulcimen-staging/mysql-ep.yaml create mode 100755 k8s/nginx-demo/apply.sh create mode 100755 k8s/nginx-demo/delete.sh create mode 100644 k8s/nginx-demo/nginx-demo-namespace.yaml create mode 100644 k8s/nginx-demo/nginx-demo-resource-quota.yaml create mode 100644 k8s/nginx-demo/nginx-deployment.yaml create mode 100644 k8s/nginx-demo/nginx-node-port-service.yaml create mode 100644 k8s/web/node-port.yaml create mode 100644 nginx/Dockerfile.nginx create mode 100644 nginx/index.html diff --git a/.github/manifests/fulcimen-load-balancer-service.yaml b/.github/manifests/fulcimen-load-balancer-service.yaml new file mode 100644 index 0000000..334a76f --- /dev/null +++ b/.github/manifests/fulcimen-load-balancer-service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: fulcimen + name: web +spec: + selector: + app: fulcimen + ports: + - port: 80 + targetPort: 3000 + type: LoadBalancer \ No newline at end of file diff --git a/.github/manifests/fulcimen-rails-deployment.yaml b/.github/manifests/fulcimen-rails-deployment.yaml new file mode 100644 index 0000000..6c611f0 --- /dev/null +++ b/.github/manifests/fulcimen-rails-deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: fulcimen + name: rails +spec: + replicas: 1 + selector: + matchLabels: + app: fulcimen + template: + metadata: + labels: + app: fulcimen + spec: + containers: + - image: docker.pkg.github.com/mlibrary/heliotropium/fulcimen:d56befee705bacbb6306f8bd8bea597f31608636 + name: heliotropium + ports: + - containerPort: 3000 \ No newline at end of file diff --git a/.github/workflows/delete-workflow-runs.yaml b/.github/workflows/delete-workflow-runs.yaml new file mode 100644 index 0000000..1cd805d --- /dev/null +++ b/.github/workflows/delete-workflow-runs.yaml @@ -0,0 +1,19 @@ +name: delete-workflow-runs +on: + workflow_dispatch: + inputs: + days: + description: 'Number of days.' + required: true + default: 90 + +jobs: + del_runs: + runs-on: ubuntu-latest + steps: + - name: Delete workflow runs + uses: Mattraks/delete-workflow-runs@main + with: +# token: ${{ secrets.AUTH_PAT }} +# repository: ${{ github.repository }} + retain_days: ${{ github.event.inputs.days }} \ No newline at end of file diff --git a/.github/workflows/deploy-branch-to-testing.yaml b/.github/workflows/deploy-branch-image-to-testing.yaml similarity index 86% rename from .github/workflows/deploy-branch-to-testing.yaml rename to .github/workflows/deploy-branch-image-to-testing.yaml index 11a0c66..7cbab62 100644 --- a/.github/workflows/deploy-branch-to-testing.yaml +++ b/.github/workflows/deploy-branch-image-to-testing.yaml @@ -1,4 +1,4 @@ -name: deploy-branch-to-testing +name: deploy-branch-image-to-testing on: workflow_dispatch @@ -25,8 +25,8 @@ jobs: kubectl config set-credentials default --token=`echo ${{ secrets.TOKEN_BASE64 }} | base64 -d` kubectl config set-context default --cluster=cluster --user=default --namespace=`echo ${{ secrets.NAMESPACE_BASE64 }} | base64 -d` kubectl config use-context default - - name: Deploy - run: | kubectl config view kubectl config current-context -# kubectl set image deployment web web=docker.pkg.github.com/mlibrary/patron_account/patron_account:${{ steps.tag_check.outputs.tag }} \ No newline at end of file + - name: Deploy + run: | + kubectl set image deployment rails heliotropium=docker.pkg.github.com/mlibrary/heliotropium/fulcimen:d56befee705bacbb6306f8bd8bea597f31608636 \ No newline at end of file diff --git a/.github/workflows/deploy-web-nginx-to-testing.yaml b/.github/workflows/deploy-web-nginx-to-testing.yaml new file mode 100644 index 0000000..86bb98c --- /dev/null +++ b/.github/workflows/deploy-web-nginx-to-testing.yaml @@ -0,0 +1,37 @@ +name: deploy-web-nginx-to-testing + +on: workflow_dispatch + +jobs: + deploy: + runs-on: ubuntu-latest + environment: fulcrum-testing + steps: + - name: GITHUB_SHA + run: echo "$GITHUB_SHA" + - name: GITHUB_REF + run: echo "$GITHUB_REF" + - name: SECRETS + env: + SECRETS: ${{ toJson(secrets) }} + run: echo "$SECRETS" + - name: Setup Kubectl + uses: azure/setup-kubectl@v1 + - name: Authenticate with kubernetes + run: | + mkdir -p ${HOME}/.kube/certs/cluster + echo ${{ secrets.CA_CRT_BASE64 }} | base64 -d > ${HOME}/.kube/certs/cluster/k8s-ca.crt + kubectl config set-cluster cluster --certificate-authority=${HOME}/.kube/certs/cluster/k8s-ca.crt --server=`echo ${{ secrets.SERVER_URL_BASE64 }} | base64 -d` + kubectl config set-credentials default --token=`echo ${{ secrets.TOKEN_BASE64 }} | base64 -d` + kubectl config set-context default --cluster=cluster --user=default --namespace=`echo ${{ secrets.NAMESPACE_BASE64 }} | base64 -d` + kubectl config use-context default + kubectl config view + kubectl config current-context + - name: Deploy + run: | + kubectl delete deployments --all + kubectl delete services --all + kubectl delete pods --all + kubectl create deployment web --image=nginx --port=80 + kubectl expose deployment web + kubectl set image deployment web nginx=docker.pkg.github.com/mlibrary/heliotropium/nginx:latest \ No newline at end of file diff --git a/.github/workflows/echo-env-context-to-json.yaml b/.github/workflows/echo-env-context-to-json.yaml index 8cea70f..5e30c8c 100644 --- a/.github/workflows/echo-env-context-to-json.yaml +++ b/.github/workflows/echo-env-context-to-json.yaml @@ -5,11 +5,16 @@ on: workflow_dispatch jobs: echo: runs-on: ubuntu-latest + environment: fulcrum-testing steps: - name: GITHUB_SHA run: echo "GITHUB_SHA $GITHUB_SHA" - name: GITHUB_REF run: echo "GITHUB_REF $GITHUB_REF" + - name: SECRETS + env: + SECRETS: ${{ toJson(secrets) }} + run: echo "$SECRETS" - name: Dump GitHub context env: GITHUB_CONTEXT: ${{ toJson(github) }} diff --git a/.github/workflows/package-nginx-image.yaml b/.github/workflows/package-nginx-image.yaml new file mode 100644 index 0000000..7815307 --- /dev/null +++ b/.github/workflows/package-nginx-image.yaml @@ -0,0 +1,23 @@ +name: package-nginx-image + +on: workflow_dispatch + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Present Working Directory + run: pwd + - name: Build and Publish + uses: craftech-io/package-action@v3.1.0 + id: url-GPR + with: + access_token: ${{ secrets.GITHUB_TOKEN }} + context: ./nginx + dockerfile: ./nginx/Dockerfile.nginx + image_name: nginx + tags: latest + - name: imageURL + run: echo ${{ steps.url-GPR.outputs.imageURL }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a6b82ba --- /dev/null +++ b/Dockerfile @@ -0,0 +1,62 @@ +#Start with Ruby 2.7.2 Image +FROM ruby:2.7.2 + +#Set up variables for creating a user to run the app in the container +ARG UNAME=app +ARG UID=1000 +ARG GID=1000 + +#This is so rails can install properly +RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \ + apt-transport-https + +#Download node at the preferred version; Download Yarn +RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - +RUN curl https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - +RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list + +# Install Node and Vim. Vim is optional, but can be nice to be able to look +# to be able to actually look at files in the container. +RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \ + nodejs \ + yarn \ + vim + +#So we can bundle install +RUN gem install bundler:2.1.4 + +#Create the group for the user +RUN groupadd -g ${GID} -o ${UNAME} + +#Create the User and assign /app as its home directory +RUN useradd -m -d /app -u ${UID} -g ${GID} -o -s /bin/bash ${UNAME} + + +#Create a /gems directory; Putting it here makes it easer to create a gems volume. +RUN mkdir -p /gems && chown ${UID}:${GID} /gems + +#Change to that User; Waited until this step because the app user doesn't +#have the authority to great the /gems directory that was done above. +USER $UNAME + +#Tell bundler to use the /gems directory +ENV BUNDLE_PATH /gems + +#Copy the Gemfile and Gemfile.lock from the Host machine into the /app directory; +COPY --chown=${UID}:${GID} Gemfile* /app/ + +#cd to app +WORKDIR /app + +#Install the Gems. Notice that this is done when only Gemfile and +#Gemfile.lock are in the /app directory +RUN bundle install + +#Copy all of the files in the current Host directory into /app +COPY --chown=${UID}:${GID} . /app + +#Set up Placeholder Environment Variables; These will be overwritten +#by Docker Compose and in production + +#Run the application +CMD ["bin/rails", "s", "-b", "0.0.0.0"] \ No newline at end of file diff --git a/Dockerfile.noah b/Dockerfile.noah new file mode 100644 index 0000000..d58a529 --- /dev/null +++ b/Dockerfile.noah @@ -0,0 +1,58 @@ +FROM ruby:2.6 +ARG UNAME=app +ARG UID=1000 +ARG GID=1000 +ARG APP_HOME=/app +ARG GEM_HOME=/gems + +# Adapted from https://medium.com/hackernoon/preventing-race-conditions-in-docker-781854121ed3 +ENV DOCKERIZE_VERSION=v0.5.0 +RUN wget -O - \ + https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ + | tar -C /usr/local/bin -xzvf - + +RUN wget -q -O- https://dl.yarnpkg.com/debian/pubkey.gpg | \ + apt-key add - && \ + echo "deb https://dl.yarnpkg.com/debian/ stable main" > \ + /etc/apt/sources.list.d/yarn.list && \ + apt-get update && \ + apt-get install -yqq --no-install-recommends \ + apt-transport-https \ + nodejs \ + yarn && \ + rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/locale /usr/share/man +RUN gem install bundler + +RUN groupadd -g $GID -o $UNAME +RUN useradd -m -d /home/app -u $UID -g $GID -o -s /bin/bash $UNAME +RUN mkdir -p $APP_HOME && chown $UID:$GID $APP_HOME +RUN mkdir -p $GEM_HOME && chown $UID:$GID $GEM_HOME + +ENV BUNDLE_GEMFILE=${APP_HOME}/Gemfile +ENV BUNDLE_JOBS=2 +ENV BUNDLE_PATH=${GEM_HOME} +ENV DB_VENDOR=mysql +ENV DB_ADAPTER=mysql2 +ENV MYSQL_PORT=3306 +ENV MYSQL_HOST=db +ENV MYSQL_USER=helio +ENV MYSQL_PASSWORD=helio +ENV MYSQL_DATABASE=helio +ENV RAILS_ENV=development + +RUN mkdir -p ${APP_HOME} ${BUNDLE_PATH} +WORKDIR ${APP_HOME} + +USER $UNAME +COPY --chown=$UID:$GID Gemfile* ${APP_HOME}/ +RUN bundle install + +# Note that docker-compose.yml mounts /app/node_modules like the gem cache +COPY --chown=$UID:$GID package.json yarn.lock ${APP_HOME}/ +RUN yarn install --check-files + +COPY --chown=$UID:$GID . ${APP_HOME} + +CMD dockerize -wait tcp://${MYSQL_HOST}:${MYSQL_PORT} -timeout 5m && \ + bundle exec rake db:migrate && \ + bundle exec rails server --binding 0.0.0.0 --port 3000 diff --git a/k8s/fulcimen-demo/apply.sh b/k8s/fulcimen-demo/apply.sh new file mode 100755 index 0000000..59bba47 --- /dev/null +++ b/k8s/fulcimen-demo/apply.sh @@ -0,0 +1,7 @@ +#!/bin/bash +kubectl apply -f fulcimen-demo-namespace.yaml +#kubectl apply -f fulcimen-demo-resource-quota.yaml +kubectl apply -f mysql-external-name-service.yaml +kubectl apply -f mysql-client-alpine-pod.yaml +kubectl apply -f fulcimen-deployment.yaml +kubectl apply -f fulcimen-node-port-service.yaml \ No newline at end of file diff --git a/k8s/fulcimen-demo/delete.sh b/k8s/fulcimen-demo/delete.sh new file mode 100755 index 0000000..37ba36c --- /dev/null +++ b/k8s/fulcimen-demo/delete.sh @@ -0,0 +1,7 @@ +#!/bin/bash +kubectl delete -f fulcimen-node-port-service.yaml +kubectl delete -f fulcimen-deployment.yaml +kubectl delete -f mysql-client-alpine-pod.yaml +kubectl delete -f mysql-external-name-service.yaml +#kubectl delete -f fulcimen-demo-resource-quota.yaml +kubectl delete -f fulcimen-demo-namespace.yaml diff --git a/k8s/fulcimen-demo/fulcimen-demo-namespace.yaml b/k8s/fulcimen-demo/fulcimen-demo-namespace.yaml new file mode 100644 index 0000000..701e093 --- /dev/null +++ b/k8s/fulcimen-demo/fulcimen-demo-namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: fulcimen-demo \ No newline at end of file diff --git a/k8s/fulcimen-demo/fulcimen-demo-resource-quota.yaml b/k8s/fulcimen-demo/fulcimen-demo-resource-quota.yaml new file mode 100644 index 0000000..8dfbf49 --- /dev/null +++ b/k8s/fulcimen-demo/fulcimen-demo-resource-quota.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: ResourceQuota +metadata: + name: fulcimen-demo + namespace: fulcimen-demo +spec: + hard: + requests.cpu: "4" + requests.memory: 8Gi + limits.cpu: "8" + limits.memory: 16Gi \ No newline at end of file diff --git a/k8s/fulcimen-demo/fulcimen-deployment.yaml b/k8s/fulcimen-demo/fulcimen-deployment.yaml new file mode 100644 index 0000000..cabb0ea --- /dev/null +++ b/k8s/fulcimen-demo/fulcimen-deployment.yaml @@ -0,0 +1,34 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: fulcimen + name: fulcimen-deployment + namespace: fulcimen-demo +spec: + replicas: 1 + selector: + matchLabels: + app: fulcimen + template: + metadata: + annotations: + imageregistry: "https://hub.docker.com/" + labels: + app: fulcimen + spec: + containers: + - name: heliotropium + image: gkostin1966/heliotropium:0.0.1 + env: + - name: DATABASE_URL + value: "mysql2://mysql/heliotropium_development" + ports: + - containerPort: 3000 +# resources: +# limits: +# memory: "2Gi" +# cpu: "1000m" +# requests: +# memory: "1Gi" +# cpu: "500m" \ No newline at end of file diff --git a/k8s/fulcimen-demo/fulcimen-node-port-service.yaml b/k8s/fulcimen-demo/fulcimen-node-port-service.yaml new file mode 100644 index 0000000..476c0dd --- /dev/null +++ b/k8s/fulcimen-demo/fulcimen-node-port-service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: fulcimen + name: fulcimen-node-port + namespace: fulcimen-demo +spec: + ports: + - nodePort: 30000 # externally exposed port e.g. localhost:30080 + port: 3000 # static node port (virtual or physical machine) e.g. docker-desktop + protocol: TCP + targetPort: 3000 # container port e.g. deployment/fulcimen + selector: + app: fulcimen + type: NodePort \ No newline at end of file diff --git a/k8s/fulcimen-demo/mysql-client-alpine-pod.yaml b/k8s/fulcimen-demo/mysql-client-alpine-pod.yaml new file mode 100644 index 0000000..82ca633 --- /dev/null +++ b/k8s/fulcimen-demo/mysql-client-alpine-pod.yaml @@ -0,0 +1,51 @@ +apiVersion: v1 +kind: Pod +metadata: + labels: + app: fulcimen + name: mysql-client + namespace: fulcimen-demo +spec: + containers: + - image: alpine + name: alpine + command: ["sh"] + args: ["-c", "sleep 100000"] +# Sleep long enough to use for host MySQL connection testing +# kubectl -c alpine -it exec mysql-client --namespace=fulcimen-demo -- sh +# Use ping to test connection to host +# ping mysql +# Install mysql-client to test connection to host MySQL +# apk --no-cache add mysql-client +# mysql -h mysql -u root +# Welcome to the MariaDB monitor. Commands end with ; or \g. +# Your MySQL connection id is 19 +# Server version: 8.0.23 Homebrew +# +# Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. +# +# Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. +# MySQL [(none)]> show databases; +# +--------------------------------+ +# | Database | +# +--------------------------------+ +# | gkostin_heliotrope_development | +# | gkostin_heliotrope_test | +# | heliotrope_development | +# | heliotrope_test | +# | heliotropium_development | +# | heliotropium_test | +# | information_schema | +# | mysql | +# | performance_schema | +# | swapmeet_development | +# | swapmeet_test | +# | sys | +# | thyrax_development | +# | thyrax_test | +# +--------------------------------+ +# 14 rows in set (0.004 sec) +# +# MySQL [(none)]> quit +# Bye +# exit \ No newline at end of file diff --git a/k8s/fulcimen-demo/mysql-external-name-service.yaml b/k8s/fulcimen-demo/mysql-external-name-service.yaml new file mode 100644 index 0000000..5ebafae --- /dev/null +++ b/k8s/fulcimen-demo/mysql-external-name-service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: fulcimen + name: mysql + namespace: fulcimen-demo +spec: + type: ExternalName + externalName: host.docker.internal +# Commented out line 4 and added line 5 to /usr/local/etc/my.cnf +# 1 # Default Homebrew MySQL server config +# 2 [mysqld] +# 3 # Only allow connections from localhost +# 4 # bind-address = 127.0.0.1 +# 5 bind-address = 0.0.0.0 +# So MySQL will accept external connections \ No newline at end of file diff --git a/k8s/fulcimen-staging/mysql-ep.yaml b/k8s/fulcimen-staging/mysql-ep.yaml new file mode 100644 index 0000000..5442270 --- /dev/null +++ b/k8s/fulcimen-staging/mysql-ep.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Endpoints +metadata: + labels: + app: heliotropium + name: mysql-ep + namespace: heliotropium-demo +subsets: + - addresses: + - ip: 192.0.2.42 + ports: + - port: 3306 \ No newline at end of file diff --git a/k8s/nginx-demo/apply.sh b/k8s/nginx-demo/apply.sh new file mode 100755 index 0000000..d6bab73 --- /dev/null +++ b/k8s/nginx-demo/apply.sh @@ -0,0 +1,5 @@ +#!/bin/bash +kubectl apply -f nginx-demo-namespace.yaml +kubectl apply -f nginx-demo-resource-quota.yaml +kubectl apply -f nginx-deployment.yaml +kubectl apply -f nginx-node-port-service.yaml \ No newline at end of file diff --git a/k8s/nginx-demo/delete.sh b/k8s/nginx-demo/delete.sh new file mode 100755 index 0000000..0150121 --- /dev/null +++ b/k8s/nginx-demo/delete.sh @@ -0,0 +1,5 @@ +#!/bin/bash +kubectl delete -f nginx-node-port-service.yaml +kubectl delete -f nginx-deployment.yaml +kubectl delete -f nginx-demo-resource-quota.yaml +kubectl delete -f nginx-demo-namespace.yaml diff --git a/k8s/nginx-demo/nginx-demo-namespace.yaml b/k8s/nginx-demo/nginx-demo-namespace.yaml new file mode 100644 index 0000000..66fe647 --- /dev/null +++ b/k8s/nginx-demo/nginx-demo-namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: nginx-demo \ No newline at end of file diff --git a/k8s/nginx-demo/nginx-demo-resource-quota.yaml b/k8s/nginx-demo/nginx-demo-resource-quota.yaml new file mode 100644 index 0000000..7e8fac9 --- /dev/null +++ b/k8s/nginx-demo/nginx-demo-resource-quota.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: ResourceQuota +metadata: + name: nginx-demo-resource-quota + namespace: nginx-demo +spec: + hard: + requests.cpu: "4" + requests.memory: 8Gi + limits.cpu: "8" + limits.memory: 16Gi \ No newline at end of file diff --git a/k8s/nginx-demo/nginx-deployment.yaml b/k8s/nginx-demo/nginx-deployment.yaml new file mode 100644 index 0000000..d6095eb --- /dev/null +++ b/k8s/nginx-demo/nginx-deployment.yaml @@ -0,0 +1,31 @@ +apiVersion: apps/v1 # Version of the API to use. +kind: Deployment # "top-level" API type. +metadata: + labels: + app: nginx # Tag deployment with app label + name: nginx-deployment # Unique name of deployment object within namespace. + namespace: nginx-demo # Unique name of namespace of deployment object. +spec: # Desired state of deployment. + replicas: 1 # Number of desired pods. + selector: # Label selector for pods. + matchLabels: # Existing ReplicaSets whose pods are selected by this will be the ones affected by this deployment. + app: nginx # It must match the pod template's labels. + template: # Template describes the pods that will be created. + metadata: + annotations: + imageregistry: "https://hub.docker.com/" + labels: + app: nginx # Selector label + spec: + containers: + - name: nginx + image: nginx + ports: + - containerPort: 80 + resources: + limits: + memory: "2Gi" + cpu: "1000m" + requests: + memory: "1Gi" + cpu: "500m" \ No newline at end of file diff --git a/k8s/nginx-demo/nginx-node-port-service.yaml b/k8s/nginx-demo/nginx-node-port-service.yaml new file mode 100644 index 0000000..2431992 --- /dev/null +++ b/k8s/nginx-demo/nginx-node-port-service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: nginx + name: nginx-node-port + namespace: nginx-demo +spec: + ports: # Lists of named subobjects preferred over maps + - nodePort: 30000 # externally exposed port e.g. localhost:30080 + port: 80 # static node port (virtual or physical machine) e.g. docker-desktop + protocol: TCP + targetPort: 80 # container port e.g. deployment/nginx + selector: + app: nginx + type: NodePort diff --git a/k8s/web/node-port.yaml b/k8s/web/node-port.yaml new file mode 100644 index 0000000..65c15c6 --- /dev/null +++ b/k8s/web/node-port.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app: web + name: web +spec: + ports: # Lists of named subobjects preferred over maps + - nodePort: 30000 # externally exposed port e.g. localhost:30080 + port: 80 # static node port (virtual or physical machine) e.g. docker-desktop + protocol: TCP + targetPort: 80 # container port e.g. deployment/nginx + selector: + app: web + type: NodePort diff --git a/nginx/Dockerfile.nginx b/nginx/Dockerfile.nginx new file mode 100644 index 0000000..6f2981b --- /dev/null +++ b/nginx/Dockerfile.nginx @@ -0,0 +1,2 @@ +FROM nginx:latest +COPY ./index.html /usr/share/nginx/html/index.html diff --git a/nginx/index.html b/nginx/index.html new file mode 100644 index 0000000..1195e28 --- /dev/null +++ b/nginx/index.html @@ -0,0 +1,9 @@ + + + + +

nginx

+

hello

+ + + \ No newline at end of file