Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Build your Kubernetes armory with Minikube, Kail, and Kubens

April 16, 2019
Kamesh Sampath
Related topics:
Developer ToolsKubernetes

Share:

    Kubernetes has grown to be a de facto development platform for building cloud-native applications. As developers, we want to be productive from the word go, or, shall we say, from the word code. But to be productive, we must be armed with the right set of tools. In this article, I will take a look at three important tools that should become part of your Kubernetes tool chest, or armory.

      Minikube

    When you think of Kubernetes, several questions may come to mind, including:

    1. How do I set up each and every Kubernetes component?
    2. How do I configure Kubernetes correctly?
    3. Even if I set up and configure Kubernetes correctly, do I have to do this every time?

    The answer is Minikube, which can help you easily set up a proper Kubernetes node suitable for your everyday development needs.

    To get going, the minikube start command just brings up a single-node Kubernetes environment with 2GB RAM, 2 CPUS, and a disk of 20GB.

    Running the command:

    minikube ip

    will let you know the IP of the Kubernetes node that is part of the virtual machine started by Kubernetes.

    I was able to deploy small lightweight applications with the default config, but then one day I needed to build a bigger Kubernetes node with a memory of 8GB RAM, 4 CPUS, and a disk of size 50GB. To get this kind of configuration, you can use:

    minikube start --memory=8192 --cpus=4 --disk-size=50g

    As you become a more experienced Kubernetes user, you will have a Kubernetes environment for one set of applications, another for a different set of applications, and so on. This is super easy with what is called a “profile” in Minikube. Let's create a profile called sword, which will hold all our "cutting-edge" technology applications. To create your sword profile, you can just run the same minikube start but with a -p like:

    minikube start -p sword --memory=8192 --cpus=4 --disk-size=50g

    Minikube by default stores all files, config, and other related settings of the sword profile under $MINIKUBE_HOME/profiles/sword.  $MINIKUBE_HOME is an environment variable that Minikube understands to be the place to store the Minikube virtual machine artifacts, such as configs, disks, etc.,

    A good first step! Now, I will teach you a tip. Here's how to invoke a Kubernetes service, for example, a "customer" using Minikube:

    minikube service customer

    When learning how to use these tools; however, we need to consider other tools as well.

    Kubens: Switch Kubernetes namespaces

    Kubernetes by default has the many namespaces, such as default, kube-public, and kube-system. Any resource you create without a namespace is created in namespace default.

    For example, executing the following command without --namespace or -n option, would create the "dagger" configmap in default namespace.

     kubectl create configmap dagger --from-literal size=small

    In considering application development priorities, we quite often miss this subtle behavior.  That's when we start to spend sleepless nights and weekends wondering, why is this not working for me?

    By adding kubens to our armory, we can set the namespace in which we will be creating the resources. Let's say we have a namespace called vikings; we can set that to be namespace for all our resources just by running the kubens vikings command. When we then try to create any resource without the --namespace or -n option, Kubernetes will by default create it in the vikings namespace.

    If you have to get back to the previous namespace, it's as simple as running the command kubens - (similar to Bash cd -).

    Kail: Watching logs

    Our tool chest is filling up nicely, but we still lack vital tools. As part of our everyday job, we need to analyze the logs of the pods.

    Kubectl does have log commands, but that is primitive. We need a tool that can help us to filter logs based on some criteria, for example, pods that belong to Kubernetes deployment.

    By adding Kail to our toolkit, we will get even more power via filters to query and analyze the logs:

    • Pods by deployment — For example, get logs from pods that are part of the deployment dagger in namespace sword:
    kail -n sword -d dagger
    • Pods by service — Get logs of pods that are part of the service battle:
    kail -n sword --svc battle
    • Pods by label — Get logs of all pods with "size=large":
    kail -n sword --label size=large

    The filters could also be combined to filter the logs further. For example, suppose you want to view all the logs of service “battle” that do not have “size=large”:

    kail -n sword --svc battle --ignore size=large

    Kail has lot of other filters just run kail --help for more details. When I first started to use Kail, sometimes I didn't see the logs, but then I realized that my host time and Minikube time are different, so I had to add --since flag to my commands. For example, to query the pod logs for the last 2 hours (Kubernetes node time), use:

    kail -n sword --svc battle --since=2h

    That’s it for this article. Armed with these tools, we're ready to succeed in our code battle. In my next article, we will add more tools to our armory and expand our skills even more. Until then, happy coding!

    Tutorials

    Here are tutorials for our Kubernetes warriors:

    1. Istio: github.com/redhat-developer-demos/istio-tutorial
    2. Knative: github.com/redhat-developer-demos/knative-tutorial
    Last updated: September 3, 2019

    Recent Posts

    • More Essential AI tutorials for Node.js Developers

    • How to run a fraud detection AI model on RHEL CVMs

    • How we use software provenance at Red Hat

    • Alternatives to creating bootc images from scratch

    • How to update OpenStack Services on OpenShift

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue