Deploy to Kubernetes Engine
Kubernetes Engine allows you to create a cluster of machines and deploy any number of applications to it. Kubernetes abstracts the details of managing machines and allows you to automate the deployment of your applications with simple CLI commands.
To deploy an application to Kubernetes, you first need to create the cluster. Then you need to add a configuration file for each application you will deploy to the cluster.
On the Navigation menu (Navigation menu icon), click Kubernetes Engine. If a message appears saying the Kubernetes API is being initialized, wait for it to complete.
Click Create.
In the Create Cluster dialog box, to the right of the GKE Standard option, click Configure.
Accept all the defaults, and click Create. It will take a couple of minutes for the Kubernetes Engine cluster to be created. When the cluster is ready, a green check appears.
Click the three dots to the right of the cluster and then click Connect.
In the Connect to the cluster screen, click Run in Cloud Shell. This opens Cloud Shell with the connect command entered automatically.
Press Enter to connect to the cluster.
To test your connection, enter the following command:
kubectl get nodes
This command simply shows the machines in your cluster. If it works, you're connected.
In Cloud Shell, click Open Editor (Cloud Shell Editor icon).
Expand the training-data-analyst/courses/design-process/deploying-apps-to-gcp folder in the navigation pane on the left. Then, click main.py to open it.
In the main() function, change the title to Hello Kubernetes Engine as shown below:
Save your change.
Add a file named kubernetes-config.yaml to the training-data-analyst/courses/design-process/deploying-apps-to-gcp folder.
Paste the following code in that file to configure the application:
Note: In the first section of the YAML file above, you are configuring a deployment. In this case, you are deploying 3 instances of your Python web app. Notice the image attribute. You will update this value with your image in a minute after you build it. In the second section, you are configuring a service of the type "load balancer". The load balancer will have a public IP address. Users will access your application through the load balancer.
For more information on Kubernetes deployments and services, see the links below:
0 Comments