Getting Started With Skaffold

Read Time:4 Minute, 30 Second

Whether you’re testing local deployments to ensure that a containerized application is working as expected or you’re looking to deploy a containerized workflow to production, you need an automatic way to complete these tasks.

Not to mention, you probably need a way to automatically build container images.

That’s where Skaffold can come into play.

In this blog post, you’ll learn about what Skaffold is and a few different ways that you can utilize it to make deployments easier.

Prerequisites

To follow along from a hands-on perspective, you should have:

  • A Kubernetes cluster running. This can be Minikube or a production-level cluster.

What Is Skaffold?

Scaffold was originally created to make local Kubernetes development easier.

The idea for this project was for the continuous change in container images. Once code is updated, there needs to be a way to automatically update the container image. For example, if you’re going from v1.1 to v1.2, you don’t want to have to run docker build . on a Dockerfile manually. Instead, you want an automated way to build the new container image and have it deployed.

That’s exactly what Skaffold does.

It looks at local or remote directories where code exists and if the code changes, Skaffold can automatically create a new containerized image and then deploy it to your Kubernetes cluster.

Essentially, it’s like GitOps for your container images. Whereas standard GitOps will look at a Kubernetes Manifest or a Kubernetes resource being created with a client and deploy any changes made, Skaffold will look at any application changes, push those changes to the container image, and then the container image will be updated and deployed in the Kubernetes Manifest.

Docker Setup

To push a container image to a registry, like Dockerhub, you’ll need to log into the registry and specify your registry in your Kubernetes Manifest, which you’ll see in the upcoming section.

Ensure that you log into your container registry on your terminal.

For example, if you’re using Dockerhub, run the following command:

Enter fullscreen mode Exit fullscreen mode

The App

Because Skaffold is made for Kubernetes and containers, you will need:

  • Application code that’s ready to containerize.
  • A Kubernetes Manifest to utilize the containerized app.

To keep the app simple (although this process will work with other apps as well), you can take the Go code below and store it in a directory.

Enter fullscreen mode Exit fullscreen mode

In the same directory, create a new Kubernetes Manifest called goapp.yaml and store the following Manifest.

In the Manifest below, for the value of image:, you’ll see a container registry and a container image name. You should use your own as in the previous section you logged into your container registry, but there’s an example in the Manifest below that shows my Dockerhub username (thenjdevopsguy) along with the container image name that I want to push my container image to after I build it with skaffold, which is coming up in a future section of this blog post.

Enter fullscreen mode Exit fullscreen mode

Notice how the app name is gowebapp. That piece of information will come up in the next section.

Installing Skaffold

The installation will be different for each operating system. Below is an example of installing on MacOS, but if you’re on a different operating system, check out the installation methods here: https://skaffold.dev/docs/install/

The code below installs Skaffold on a MacOS machine with an M1 chip.

curl -Lo skaffold https://storage.googleapis.com/skaffold/builds/latest/skaffold-darwin-arm64 &&
sudo install skaffold /usr/local/bin/

Using Skaffold

Once Skaffold is installed, the app code is prepared, and the Kubernetes Manifest is written, you can start the process of using Skaffold.

First, ensure that you’re cd into the same directory as the app code and k8s manifest.

Getting Started With Skaffold

Next, run the initialization command.

skaffold init

You’ll see an output similar to the screenshot below. Notice how it’s using the image name that you specified in the Kubernetes Manifest.

Skaffold is building the container image via a Cloud Native Buildpack, which is a way to build container images directly from code without needing a Dockerfile.

Click y like in the screenshot below.

Image description

You’ll now see a configuration similar to the screenshot below in the same directory as your app and k8s manifest. It contains the container image name, the cloud native buildpack builder, and the k8s manifest.

Image description

Next, run the following command to start building the container image which will also push the container image to your container registry and deploy it to the Kubernetes cluster that’s on your current context via your Kubeconfig.

Enter fullscreen mode Exit fullscreen mode

If you come across the skaffold run command and are wondering what the difference is, here it is: skaffold run builds and deploys once whereas skaffold dev triggers the watch loop build and deploy workflows.

You’ll see an output similar to the screenshots below which shows that the container image is being built for the Go app.

Image description
Image description

The whole build process should take a few minutes.

Once complete, you should see that the app deployed to Kubernetes and you should also see that the container image now exists in your container registry.

Source: https://dev.to/thenjdevopsguy/getting-started-with-skaffold-5120

WP Ad Inserter plugin for WordPress

Tag Cloud

Java Java Logical Programs OTP Generation in Java python Recursion youtube video ASCII Upper and Lower Case blockchain javascript graph learn to code software development Successful Software Engineers breadth first search Java Array Programs Java Programs Uncategorized android ios programming kotlin web-development django data sql cybersecurity database swiftui serverless aws swift rust react background-position gradients loader mask grid nth-child pseudo elements indieweb WordPress Print Array without brackets C++ factorial Java String Programs Final Keyword Static Variable Axie Infinity Cryptokitties NFT games tool inserting MISC Tips Codes python code python projects python3 system info python project Bigginers How to Do Integrations Payment Gateways PHP checkout page in php Implement stripe payment gateway in Step by step in PHP integrate stripe gatway in php mysql payment gateway integration in php step by step payment gateway integration in php step by step with source code payment gateway integration in website PHP Integrate Stripe Payment Gateway Tutorial PHP shopping cart checkout code shopping cart in php stripe php checkout PHP/MySQL/JSON best international payment gateway does google pay accept international payments how to accept international payments in india paytm payment gateway razorpay codeigniter github razorpay custom checkout github razorpay get payment details razorpay integration in codeigniter github razorpay international payments Razorpay payment gateway integration in CodeIgniter razorpay payment gateway integration in php code Razorpay payment gateway integration with PHP and CodeIgniter Razorpay payment gateway setup in CodeIgniter Library & Frameworks Tips & Tricks UI/UX & Front-end coding birds online html code for google sign in login with google account in PHP login with google account using javascript login with google account using javascript codeigniter login with google account using php login with google account using php source code
Web Security 101 – Part 1: Secrets Previous post Web Security 101 – Part 1: Secrets
Developer Health: Tips for dealing with workplace anxieties and imposter syndrome Next post Developer Health: Tips for dealing with workplace anxieties and imposter syndrome

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.