Skip to content

Instantly share code, notes, and snippets.

Last active March 27, 2024 14:57
Show Gist options
  • Save robrich/5abd6c1261eae55476db2a15d1c2180a to your computer and use it in GitHub Desktop.
Save robrich/5abd6c1261eae55476db2a15d1c2180a to your computer and use it in GitHub Desktop.

Local Development Techniques with Kubernetes

This talk is all live demos of tools developers can use in their inner-loop, at development time to be more productive with containers.

Start Easier

Docker Compose captures the build arguments and run arguments so we can focus on our coding.

As we explore Docker Compose, we use network_mode: bridge to avoid creating a new overlay network for the compose file contents. This allows us to easily network between containers from multiple docker-compose.yaml files.

Run differently

Minikube is an alternate Docker runtime that is more compatible with nested virtualization scenarios and keeps a more modern version of Kubernetes.

After running minikube start, run minikube docker-env to get the environment variables you'll set to allow the Docker CLI to work easily with the container runtime inside Minikube.

Rebuild faster

I wish there was a docker watch ... but there isn't. Instead we can use Skaffold.

Run skaffold init to generate a yaml file, then tweak it to identify the image name to build and the kubernetes yaml file to run. You can optionally push to a remote container registry.

Visualize container contents

Dive allows you to view the files in each container layer.

docker history ... shows you the commands that were run at each layer, but it doesn't show you the container contents. We use Dive to notice that we copied in too many files, and we need to adjust the .dockerignore file.

Visualize running containers

In this section we look at 3 tools that allow us to see our cluster.

LazyDocker is a command-line tool to visualize a Docker cluster. It has really cool mouse behaviors ... that don't work in Windows, but it has great key bindings that allow you to navigate through images, volumes, containers, logs, and config.

Portainer is a great web-based tool to visualize the Docker-side of a cluster. Grab a docker-compose.yaml file, quickly spin it up, and you can visualize, remote into, and kill containers with ease on a local or remote cluster.

k9s is a command-line tool for visualizing a Kubernetes cluster from a terminal. The keyboard shortcuts are modled after vi, so get comfortable with : and esc.

Skooner (formerly k8dash) is a great way to view the Kubernetes-side of a cluster. View deployments, pods, volumes, secrets, and other k8s resources. Grab the secret you created as you spun it up to login.

Debug inside containers

VS Code Remoting allows debugging processes inside containers.

Once you have the extension installed, you can click the green icon on the bottom-left to start a sample, generate the .devcontainer folder contents, or launch VS Code from inside a container. In this mode, VS code splits in half. The UI half is running locally and handles colors, fonts, and themes. The other half is running inside the container, and handles running the app, and intellisense for your language of choice. We fire up the app to see how VS Code Remoting automatically proxies the web port to our local machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment