Today, we’ll be building on our recent coverage of the Kubernetes Ecosystem to talk more in depth about Kops. This post is a complement to our Kubernetes webinar earlier this year and follows previous posts that cover deploying applications with Helm and creating and maintaining Kubernetes clusters with Kops. Let’s begin by addressing a basic question: What is Kops?

What is Kops?

Kops is an official Kubernetes project for managing production-grade Kubernetes clusters. Kops is currently the best tool to deploy Kubernetes clusters to Amazon Web Services. The project describes itself as kubectl for clusters.

If you’re familiar with kubectl, then you’ll feel at home with Kops. It has commands for creating clusters, updating their settings, and applying changes. Kops uses declarative configuration, so it’s smart enough to know how to apply infrastructure changes to existing clusters. It also has support for cluster operational tasks like scaling up nodes or horizontally scaling the cluster. Kops automates a large part of operating Kubernetes on AWS.

Before moving on to examples, let’s look at its key features:

  • Deploy clusters to existing virtual private clouds (VPC) or create a new VPC from scratch
  • Supports public & private topologies
  • Provisions single or multiple master clusters
  • Configurable bastion machines for SSH access to individual cluster nodes
  • Built on a state-sync model for dry-runs and automatic idempotency
  • Direct infrastructure manipulation, or works with CloudFormation and Terraform
  • Rolling cluster updates
  • Supports heterogeneous clusters by creating multiple instance groups

Check out this short ASCII cast demo for more info.

Now, we’ll tackle a common scenario: Create a cluster and configure it for your use case.

Creating Your First Kubernetes Cluster on AWS

You’ll need to configure IAM permissions and an S3 bucket for the KOPS_STATE_STORE. The KOPS_STATE_STORE is the source of truth for all clusters managed by Kops. You’ll need appropriate IAM permissions so that Kops can make API calls on your behalf. I won’t cover that in this post, but you can follow the instructions here.

You’ll also need to configure DNS. Kops supports a variety of configurations. Each has its own setup instructions. AWS Route53 with an existing HostedZone is the easiest. We’ll assume that there is an existing AWS Route53 HostedZone for in these examples.

Kops clusters must be valid DNS names. Let’s create the cluster. Kops will also create the DNS record for the Kubernetes API sever at, and Keep in mind that DNS names may only be so long, so don’t use base cluster names that are too long. Everything starts with kops create. You can pass options directly to the command or write a cluster spec file. We’ll use the command line options for this exercise. Using a dedicate file is great for source control and other forms of configuration management. kops create accepts many options. We’ll start with the simplest case by only supplying the required options.

There are two required values. --zones states the GCP zones / AWS regions where to create the infrastructure. Here, eu-west-1a, eu-west-1b, eu-west-1c are specified. This instructs Kops to create infrastructure in each eu-west-1 availability zone. This is important because Kops aims to create high availability production clusters. Multiple availability zones make the cluster more reliable by protecting against failures in one availability zone.

You must also specify the cluster name. --yes confirms operations that normally prompt for confirmation. kops create adds a kubectl configuration entry for the new cluster so you’re ready to use it right away. The command is async. It will trigger infrastructure creation, but will not block it completely. Luckily, Kops includes a command to validate a cluster. You can rerun this command until it succeeds.

When everything is complete, you should see something similar to the following:

Now, you’re ready to run any kubectl command such as kubectl get pods -n kube-system. The cluster is a bit strange because it has three masters and only a single worker. Let’s update the node instance group.

Modifying Cluster Infrastructure

Remember that kops behaves like kubectl. This means that you can kops edit to edit the configuration files in your editor. The next step is to run kops update. This applies configuration changes, but does not modify running infrastructure. kops rolling-update manages updating or recreating infrastructure.

This process applies to all sorts of configuration changes. First edit, then update, and finally  rolling-update. Let’s take this for a spin by editing the node instance group to increase the number of worker nodes.

That will open a YAML file in your editor. You’ll see something similar to the following:

All we need to do is replace minSize and maxSize with appropriate values. I’ll set both values to 3 and save the file. This writes the updated file back to the KOPS_STATE_STORE. Now, we need to update the cluster. Again, we’ll supply --yes to confirm the changes.

Finally, apply the rolling-update.

That’s a bit strange. Kops says that there is no rolling-update required. This is true because we only changed the minimum and maximum number of instances in the nodes auto scaling group. This does not require any changes to the existing infrastructure. AWS simply triggers creation of two instances.

Let’s make another change that requires changing infrastructure. Imagine that the existing t2.medium instances are not cutting it. We need to scale up to meet workload requirements. To do that, we need to change the instance type. The same edit, update, and rolling-update process applies here. Let’s upgrade to m4.large. Repeat the exercise and replace t2.medium with m4.large then apply the rolling-update. Now, Kops kills each node in order to trigger creation of an up-to-date node.

Caution though! Current versions (<= 1.6) do not yet perform a real rolling update It just shuts down machines in sequence with a delay; there will be downtime Issue #37 We have implemented a new feature that does drain and validate nodes. This feature is experimental, and you can use the new feature by setting export KOPS_FEATURE_FLAGS="+DrainAndValidateRollingUpdate". This should be fixed in a future release.

This same process applies to infrastructure and configuration (such as kubelet flags or API server flags). The documentation covers specific cases:

As always, you can refer to the documentation for complete information.

Custom Cluster Infrastructures

Our example covered the most simple case, but this does not apply to all scenarios. Let’s walk through different options available to the kops create cluster.

  • --vpc and --newtork-cidr can be used when deploying to an existing AWS VPC.
  • --bastion generates a dedicated SSH jump host for SSH access to cluster instances. This is best used with --associate-public-ip=false.
  • --master-zones specifies all of the zones where masters run. This is key for HA setups.
  • --networking sets the default network. Note that your particular choice depends on your requirements and may work with the specified --topology.
  • --topology is the internal networking state. I prefer --bastion --topology=private --associate-public-ip=false --networking=weave to keep the clusters inaccessible on the public internet.

Next Steps

Kops is one the best tools that we have right now to manage Kubernetes clusters. Kops, like everything else in the Kubernetes ecosystem, is changing rapidly. The #kops channel on the Kubernetes Slack team is the best place to interact with other users. The people behind it are actively fixing bugs, introducing new features, and accepting proposals from the community. They also set aside an hour every other week to offer help and guidance to the community. They work with newcomers, help with PRs, and discuss new features, anything goes.

Add something to the agenda. They hold office hours (on Zoom video conferences) on Fridays at 5 p.m. UTC/9 a.m. US Pacific Time every other week, on odd weeks. I also recommend that you read through the issue tracker to get a feel for the known issues and more importantly the missing features.

Kops can do a lot, but it may not do everything for your use case, so be sure to do your research before diving in head first. One notable omission is the lack of pre/post install hooks for node configuration. This is required for things like pre-pulling images or installing software on nodes. This was recently fixed in a pull request, but there is no timeline for the next release at this point in time.

Kops, Kubernetes, containers, Docker and more are also discussed in the CloudAcademy 2017 office hours.

Stay tuned on the Cloud Academy blog for more Kubernetes!