Skip to main content

Docker wrapper for containerd and common commands


Why

As Kubernetes slowly moves away from Docker, it is important to know a few ctr and crictl commands in order to troubleshoot problems. I have used Docker for over 6 years in production and don't usually need to look up commands like stats, load, save, ps etc.

However, without the familiar Docker command line it can be hard to perform these tasks, especially when under pressure debugging a production issue.

So I wrote the following shell script hack below. As containerd is name spaced, some commands need to include the namespace k8s.io to provide a useful response. Containerd also knows the concept of pods, so the pause containers are not visible for certain commands.

#!/bin/bash

ARG=$1
MSG="##### No docker installed, running this for you instead:"

case $ARG in

info)
  echo "$MSG ctr version"
  ctr version
  ;;

ps)
  echo "$MSG ctr -n k8s.io containers list - or crictl pods"
  crictl pods
  ;;

rm)
  echo "$MSG ctr -n k8s.io containers rm $2"
  ctr -n k8s.io containers rm $2
  ;;

pods)
  echo "$MSG crictl pods"
  crictl pods
  ;;

images)
  echo "$MSG crictl images"
  crictl images
  ;;

inspect)
  echo "$MSG ctr -n k8s.io container info $2"
  ctr -n k8s.io container info $2
  ;;

load)
  echo "$MSG ctr -n k8s.io image import $2"
  ctr -n k8s.io image import $2
  ;;

save)
  echo "$MSG ctr -n k8s.io image export $2"
  ctr -n k8s.io image export $2
  ;;

pull)
  echo "$MSG crictl pull $2"
  crictl pull $2
  ;;

*)
  echo "$MSG sorry, command $ARG unknown"
  ;;

esac

Links

https://kubernetes.io/docs/tasks/debug-application-cluster/crictl/


Comments

Popular posts from this blog

Manual Kubernetes TLS certificate renewal procedure

Intro Kubernetes utilizes TLS certificates to secure different levels of internal and external cluster communication.  This includes internal services like the apiserver, kubelet, scheduler and controller-manager etc. These TLS certificates are created during the initial cluster installation and are usually valid for 12 months. The cluster internal certificate authority (CA) certificate is valid for ten years. There are options available to automate certificate renewals, but they are not always utilised and these certs can become out of date. Updating certain certificates may require restarts of K8s components, which may not be fully automated either. If any of these certificates is outdated or expired, it will stop parts or all of your cluster from functioning correctly. Obviously this scenario should be avoided - especially in production environments. This blog entry focuses on manual renewals / re-creation of Kubernetes certificates. For example, the api-server certificate below...

Enhancing Kubernetes Security: Enabling API Server Audit Logging

      In the ever-evolving landscape of container orchestration and management, Kubernetes remains at the forefront, empowering organizations to deploy, manage, and scale their containerized applications efficiently. However, as Kubernetes environments grow in complexity, ensuring robust security measures becomes paramount. One crucial aspect of Kubernetes security is audit logging, particularly concerning the Kubernetes API server, which serves as the primary point of interaction with the cluster. The Importance of Audit Logging Audit logging provides visibility into the activities and interactions within a Kubernetes cluster. By recording requests and responses made to the API server, audit logs offer valuable insights into user actions, system modifications, and potential security breaches. This transparency is essential for compliance with regulatory requirements such as HIPAA, GDPR, and PCI DSS, as well as for detecting and investigating security incidents. Understan...

Choosing the Right Operating System for Kubernetes

  In the realm of container orchestration, Kubernetes reigns supreme as the de facto standard. It's the go-to platform for managing containerized applications at scale. However, as you delve into the world of Kubernetes deployment, one crucial decision often overlooked is the choice of operating system (OS). While Kubernetes itself is platform-agnostic, the underlying OS can significantly impact performance, security, and overall manageability. In this guide, we'll explore various operating systems suitable for Kubernetes deployment and help you make an informed decision. 1. Linux Distributions: a. Ubuntu: Pros: Ubuntu is one of the most popular choices for Kubernetes deployment due to its widespread adoption and strong community support. It offers a balance between stability and cutting-edge features. Cons: Some argue that Ubuntu's release cycle may introduce instability, especially for production environments requiring long-term support (LTS) versions. b. CentOS/RHEL: P...