Notable Changes In Kubernetes 1.18 CLI

Notable Changes In Kubernetes 1.18 CLI

Recently I decided to pursue the CKA (Certified Kubernetes Administrator) certification. Although using [k8s] in various capacities for several years, I wanted to dive deep into understanding the inner workings and truly "master" the technology. Like many in pursuit of the CKA, I enrolled in online courses to cover key knowledge areas and identify gaps. I also practiced using Kelsey Hightower's "Kubernetes The Hard Way" tutorial. I watched online videos and read blog posts on tips & tricks, like Kubernetes co-creator Joe Beda's post on time-saving commands for generating YAML manifests.

CKA is now using Kubernetes 1.18

CKA and CKAD now running on Kubernetes 1.18

Upon registering for my exam date (coming soon), I noticed in the exam documentation it will be hosted on Kubernetes version 1.18. All of the blog posts, online tutorials, sandbox environments (thanks Linux Academy for cloud playground included with tutorials) use older versions of Kubernetes ranging from 1.13 to 1.16, but none had 1.18.

On a whim I decided to upgrade a practice cluster to the latest version and discovered many common shortcuts are no longer possible. I'm sure there are more changes, but I'll highlight the ones that I needed to find workarounds.

Changes to YAML output ( --export, --dry-run, -o yaml )

A common technique to produce a YAML file to edit a configuration is to use common flags -o yaml (output in YAML format), --dry-run (don't execute command just simulate it), --export (strip out system status information). Now the --export is deprecated, and --dry-run requires additional parameters. Furthermore, there is more content in the output that you have to "clean up".

# prior example

kubectl get deployment/nginx -o yaml --export > nginx.yaml

This produced a clean(er) version of the YAML configuration for that deployment you could then edit or version.

# new command

kubectl get deployment/nginx -o yaml > nginx.yaml

You'll notice that the --export flag is no longer available. The output also includes a LOT of extra information in the managedFields output. Unfortunately it appears there is no easy way to get a clean YAML file any more without filters, templates, etc. (please prove me wrong here as I'd love to see a better workaround)

Changes to kubectl run (pods only! --replicas --restart --port)

Another technique to quickly produce a YAML file is to use the kubectl run command, and earlier versions of kubectl it would default to a deployment. Later versions it defaulted to a pod but you could imply a deployment by adding restart and/or replicas. All of this is gone in 1.18 and now kubectl run will ONLY create pods.

# prior example to generate Deployment YAML

kubectl run my-app --image=nginx --restart=Always --replicas=3 --port=80 -o yaml --dry-run > my-app.yaml

This command would create a YAML manifest for a Deployment called "my-app" with 3 replicas of the Nginx image running on port 80. In older versions you could even add --labels="tier=frontend" flag and set the labels.

# new command to generate Deployment YAML

kubectl create deployment my-app --image=nginx -o yaml --dry-run=client > my-app.yaml

You can no longer create a Deployment using kubectl run, so now you must use the kubectl create deployment command. Even though the docs show the --replicas flag, it doesn't work so you either need to edit the file after creating it, or use the kubectl scale deployment/my-app --replicas=3 after it's running. If you need to specify a port, you can either kubectl edit the running deployment and add ports.containerPort params, or edit the YAML before creating it. The same goes for labels.

Use Here Doc and Pipes to quickly create a resource

During the exam you will be able to have one extra tab open on your browser and only access kubernetes.io (or github.com/kubernetes) sites. The recommended approach when tasked with creating a resource is find an example in the docs and copy/paste it to your clipboard and make necessary edits. If you just need to run a resource from the docs, then you can use Here Doc.

Assume you are tasked to create a pod with a Liveness Probe and you find the example in the docs like here

No alt text provided for this image

You can simply click on the "Copy" icon top-right to save the YAML to your clipboard.

No alt text provided for this image

In your terminal type "cat << EOF | kubectl apply -f -" (note the trailing hyphen). Hit ENTER and then paste the contents, then hit ENTER and add "EOF" at the end. kubectl will treat the pasted text as if it was read from a file, and create the resource.

Good luck to those pursuing the CKA!

I hope this is useful for others as they pursue their CKA. These changes are but a few, but what I noticed as the main productivity killers if you are not prepared during the timed exam. 180 minutes will go very fast once you begin, so be prepared for the current test environment and be sure to check the release notes and deprecations in the future.

To view or add a comment, sign in

More articles by Mike Sparr

  • Useful Standards For Solution Design

    Many tutorials I see online are designed to get people adopting some tool or framework quickly, yet lack the discipline…

  • Kubernetes, Helm, Istio, Prometheus, Jaeger, and Grafana on a Macbook

    Settling into my hotel in San Francisco for the week and I decided to "geek out" this evening and spin up a Kubernetes…

  • Bay Area "Magic" From Montana

    Yesterday marked my last official day at ClientHub, and next week signals the beginning of a new challenge at Capsilon.…

    3 Comments
  • Explaining Blockchain and Crypto To A Five Year Old (ELI5)

    A coworker was searching for a good ELI5 (explain like I'm five) definition of how Blockchain and crypto works. We…

  • Are You Benchmarking Your Apps?

    I've written about the benefits of automation when it comes to DevOps, and test-driven-development when it comes to…

  • Finding our "why" at ClientHub & Reazo

    Just over a year ago I decided to join forces with another real estate technology startup, and consolidate our products…

    1 Comment
  • Modern Software Startups

    What series of publications on the Internet today doesn't benefit from photos of cats? As the saying goes, there are…

    1 Comment
  • Are You Down With TDD?

    "Yeah you know me." Well perhaps Naughty By Nature didn't sing this song, but hopefully most professional software…

  • Authorization Modeling By Example

    This article is a continuation of my prior article on Security Models: Authentication and Authorization from last…

Others also viewed

Explore content categories