Site icon Learning & Doing

App Dev: Deploying the Application into Kubernetes Engine – Python

deploying

“App Dev: Deploying the Application into Kubernetes Engine – Python”

Pengantar

Google Kubernetes Engine menyediakan lingkungan terkelola untuk men-deploy, mengelola, dan menskalakan aplikasi dalam container Anda menggunakan infrastruktur Google. Lingkungan yang disediakan Kubernetes Engine terdiri dari beberapa mesin (khususnya, instance Compute Engine) yang dikelompokkan bersama untuk membentuk sebuah cluster.

Kubernetes menyediakan mekanisme untuk berinteraksi dengan klaster Anda. Anda menggunakan perintah dan sumber daya Kubernetes untuk menerapkan dan mengelola aplikasi Anda, melakukan tugas administrasi dan menetapkan kebijakan, serta memantau kesehatan beban kerja yang diterapkan.

Praktikum

Prepare the Quiz application

Clone source code in Cloud Shell

git clone https://github.com/GoogleCloudPlatform/training-data-analyst

ln -s ~/training-data-analyst/courses/developingapps/v1.2/python/kubernetesengine ~/kubernetesengine

Configure the Quiz application

cd ~/kubernetesengine/start
. prepare_environment.sh

Review the code

Navigate to training-data-analyst/courses/developingapps/v1.2/python/kubernetesengine/start.

The folder structure for the Quiz application reflects how it will be deployed in Kubernetes Engine.

The web application is in a folder called frontend.

The worker application code that subscribes to Cloud Pub/Sub and processes messages is in a folder called backend.

There are configuration files for Docker (a Dockerfile in the frontend and backend folder) and backend-deployment and frontend-deployment Kubernetes Engine .yaml files.

Create and connect to a Kubernetes Engine Cluster

Create a Kubernetes Engine cluster

Connect to the cluster

kubectl get pods

Build Docker images using Container Builder

Create the Dockerfile for the frontend and backend

FROM gcr.io/google_appengine/python
RUN virtualenv -p python3.7 /env
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH
ADD requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
ADD . /app
CMD gunicorn -b 0.0.0.0:$PORT quiz:app
FROM gcr.io/google_appengine/python
RUN virtualenv -p python3.7 /env
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH
ADD requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
ADD . /app
CMD python -m quiz.console.worker

Build Docker images with Container Builder

cd ~/kubernetesengine/start
gcloud builds submit -t gcr.io/$DEVSHELL_PROJECT_ID/quiz-frontend ./frontend/
gcloud builds submit -t gcr.io/$DEVSHELL_PROJECT_ID/quiz-backend ./backend/

Create Kubernetes deployment and service resources

Create a Kubernetes deployment file

Execute the deployment and service Files

kubectl create -f ./frontend-deployment.yaml
kubectl create -f ./backend-deployment.yaml
kubectl create -f ./frontend-service.yaml

Penutup

Sahabat Blog Learning & Doing demikianlah penjelasan mengenai App Dev: Deploying the Application into Kubernetes Engine – Python. Semoga Bermanfaat . Sampai ketemu lagi di postingan berikut nya.

Exit mobile version