Building Applications for Kubernetes
In this lesson, you’ll learn how to use tools that will shorten the feedback loop and improve velocity when developing apps for Kubernetes.
Hi, I'm Nick Stogner. I'm a Senior Cloud Architect at VMware. Today, I'm going to be talking to you about how you can improve your development workflow as you build applications on top of Kubernetes.
When I'm developing applications on Kubernetes, there's one tool in my belt that I always reach for. That tool is Skaffold. Skaffold provides me with a streamlined development experience. By this I mean, Skaffold automates the build, push, and deployment steps involved with building applications on Kubernetes. It also facilitates log retrieval. This provides me with a full feedback loop. When I change my code, I can quickly see output from the updated application. The tool also enables me to work against local or remote clusters, and it will adjust its workflow accordingly. One of my favorite features of Skaffold is it provides me with a way to declare and share my development process with other team members.
So over on the terminal, we're going to introduce Skaffold into an existing project. Here, I have two directories. The first one is [Kate 00:00:01:11], and in there I have my Kubernetes deployment manifest. I have a very simple deployment file that specifies three replicas and a corresponding service to expose the API. And over in the source directory, I have a fairly simple go API and the corresponding docker file to build my Go binary.
Okay. To get Skaffold to initialize, I just need to type in 'skaffold init.' Here you can see that Skaffold has analyzed my project. It's found my manifest files and it looks like it's also determined that the SRC directory needs to be built. Probably because it found the docker file. That all looks good. So I'm going to hit 'Y' and press 'Enter.'
All right. So you can see that Skaffold has generated its configuration file. Since I already have a local cluster running, I'm going to type in 'skaffold dev' to start the Skaffold development process. First, Skaffold builds my docker file. Then, it tags the resulting image and it uses a unique tag here. It does this because it will later apply that tag to the deployment object. It does this during the development flow because every time it rebuilds my image with a new tag it will update the deployment and trigger a redeployment. Finally, at the bottom, Skaffold will stream the logs that are coming from the pods that were deployed.
Now, let's see what happens when I update my deployment. Let's say I want five replicas rather than three. I'll save this file. Since Skaffold watches for changes, I can see that two new pods were created in the logs. I can also verify this using 'kubectl get pods.' But what happens when we change our code? Let's say that we've added some cool new features and now we want to deploy version 1.1. I'll edit the version and I'll save the file. Now, you can see on the left-hand side that Skaffold has picked up that change and it's actually rebuilding my image now. It turns out that Skaffold knows the difference between manifests and code. From watching the logs I can see that version 1.1 is now running.
Now let's see how Skaffold allows me to access my API from my local machine. So I'm going to stop the command and I'm going to rerun 'skaffold dev,' but this time I'm going to add the 'port-forward' flag. And this time Skaffold starts up the same as it did before, except this time we can see there is additional output in the logs. It looks like Skaffold is forwarding the service to my local machine on port 4503. So I can go ahead and curl that. And it looks like '[v1.1] My app says Hi.' Perfect. And on the left side, I can see that the request came through in the logs.
Okay. Now, to clean up, all I have to do is press ctrl+C and Skaffold will go ahead and remove everything that's created in Kubernetes.
Thank you for watching this lesson. I believe that one of the keys to being an efficient developer is to have a tight feedback loop when you're changing code. Skaffold is one of the tools that will enable you to do just that. Best of luck, and have fun coding.
Help us improve by sharing your thoughts.