Defining Development Environments
Working with Kubernetes Locally
Integrating GCP into our Development Workflow
Deploying to Google Cloud Platform
In this course, we will explore some of the tools available to build and manage development environments intended for deployment on Google Cloud Platform products. We will also demonstrate how to easily push builds from our local machine to Google-hosted services.
We will start the course by covering the different types of development environments and their purposes. We will touch briefly on popular software methodologies and frameworks as they relate to choices in number and type of development environments.
This course will focus on container-based application development environments, tools, and services. We will first walk through installing and using Docker and Kubernetes on your local machine. Then we will explore how to push projects to Google Cloud Run and Google Kubernetes Engine.
Writing applications using Kubernetes or Cloud Run can be further streamlined with Google Cloud Code, which provides direct IDE support for development on these platforms. We will examine how to install and use Google Cloud Code with Visual Studio Code.
- Understand the types of development environments and when to use them
- Install a container-based local development environment
- Add Google Cloud Code support to VS Code
- Push code from a local development environment and run on Google Cloud Platform using:
- Google Cloud Run
- Google Kubernetes Engine
- Google Deployment Manager
- Programmers interested in developing containerized applications on Google Cloud Platform
- Solo developers new to working on a development team
- Anyone preparing for the Google Professional Cloud DevOps Engineer certification
To get the most out of this course, you should:
- Have a Google Cloud Platform account
- Have Google Cloud SDK installed and initialized
- Be familiar with IAM role management for GCP resources
- Have Visual Studio Code, Python 3, and Git installed
Knowledge of Python would also be beneficial for scripting with GCP, but it's not essential.
In the previous lecture group, we learned how to turn a simple Python project into a Docker container, and how to deploy that container as a Kubernetes cluster on our local development machine. Even with the tools we used to simplify our workflow thus far, in practice it can still be quite tedious to work with Kubernetes in a development environment. This is because every time we make a change to our code, we have to build a new container and push it to our Kubernetes cluster, then wait for our pods to update before we can actually test those code changes.
In this lecture group, we are going to focus on the tools we can bring into our Integrated Development Environment to streamline our Kubernetes development workflow, starting with Skaffold.
Skaffold solves our development workflow problem with Kubernetes by monitoring our project and continuously deploying our updated application for us as we make changes. This way we don’t have to worry about constantly running
docker build and
kubectl commands ourselves every time we save our code.
We can install Skaffold using the
gcloud components install command the same way we installed kubectl and minikube earlier. Now we can get our project running with Skaffold by just running the command
We can see here that Skaffold has detected our Dockerfile and our kubernetes hello.yaml file, and created its own skaffold.yaml file for us. Now we can run
skaffold dev and watch Skaffold build our container and deploy it to minikube for us. If we check our minikube dashboard, we’ll find a fresh deployment of our hello app with labels managed by skaffold now, and we can see our “Hello, world!” app is running.
But now, if we go back to our main python app file and make changes, we’ll see that as soon as we save those changes Skaffold immediately rebuilds our container and redeploys our updated app to minikube for us.
Skaffold supports Cloud Native Buildpacks, which lets us build our app into a container without even needing to create a Dockerfile for our project. Buildpacks are supported across GCP products, but we’ll need to install the Pack tool in order to work with buildpacks locally. There isn’t just a downloadable executable on Windows for the Pack tool, so you will need to pick the installation option that is least obnoxious for you.
The Pack tool is cross platform, and the Buildpacks website has installation options for Mac and Linux users as well. If you are a fan of Inception, there are even instructions to run the Pack tool in a Container. I will keep things simple and install Chocolatey as a Windows command line package manager, and then install the Pack tool with the choco command.
Now that we have the Pack tool installed, we’re all set to never actually use it directly, because Skaffold will do it for us. We’ll need to find the skaffold.yaml file in our project folder and make a couple edits first. On the left you can see the yaml config that was auto generated by the
skaffold init command, and on the right is our updated skaffold.yaml for working with Buildpacks.
We no longer need to define a Dockerfile, and instead tell Skaffold we are using buildpacks, and where to find the builder we want to use. Because we are working with Python, we’ll also need to create a Procfile for our project. This is essentially the same as the last line from our Dockerfile and tells the Pack tool how to launch our app in the container.
We’ll then need to update our hello.yaml to change the container image to skaffold-buildpacks. We should also add the imagePullPolicy: Never line here, because we know the container image exists locally.
YAML files can be quite particular about indentation, so it never hurts to run a YAML linter on your changes. You can find some free online YAML linting services if one is not built into your editor. Let’s save our changes and run
skaffold dev again, and we can see skaffold has now redeployed our app using skaffold-buildpacks instead of our Dockerfile.
We’ll restart our minikube service here and we can see our app running in the browser again. Let’s make a quick edit to our python file again, and we can see skaffold redeploy our app with our changes.
With Skaffold and Buildpacks, we can almost forget about all the underlying framework of Kubernetes and begin to just focus on our code again, while our application now runs happily in a Kubernetes cluster on our local machine.
In the next video, we’ll bring together everything we’ve learned so far and integrate Kubernetes development right into our IDE.
Arthur spent seven years managing the IT infrastructure for a large entertainment complex in Arizona where he oversaw all network and server equipment and updated many on-premise systems to cloud-based solutions with Google Cloud Platform. Arthur is also a PHP and Python developer who specializes in database and API integrations. He has written several WordPress plugins, created an SDK for the Infusionsoft API, and built a custom digital signage management system powered by Raspberry Pis. Most recently, Arthur has been building Discord bots and attempting to teach a Python AI program how to compose music.