With Deployments getting bigger and bigger, networking issues are becoming harder and harder to troubleshoot.

This guide will provide basic information on debugging access to your application via the ingress controller using the ingress-nginx kubectl plugin.

Photo by Boris Smokrovic on Unsplash

As of Kubernetes 1.12, custom plugins can be written for kubectl. The Ingress Community, specifically alexkursell has done a great job at creating a plugin to help us easily debug ingress issues.

In this tutorial, we will use minikube, but all the troubleshooting examples can be performed on any Kubernetes Cluster(1.12+) with an ingress-nginx deployment(0.23.0+).

Requirements

In order to get started using this guide, the following must be installed:

VirtualBox

Minikube

Kubectl

VT-x/AMD-v virtualization must be enabled in BIOS

Internet connection on first run

Note: If you are using the ingress-nginx controller for the first time, I recommend checking out my tutorial on Getting Started with Kubernetes Ingress-Nginx on Minikube.

Installation

The ingress-nginx plugin can be installed via krew, a kubectl plugin dependency manager. In order to install krew just follow the installation guide provided in https://github.com/kubernetes-sigs/krew.

Once you have krew installed, you can get info on and install the ingress-nginx plugin by performing the following:

$ kubectl krew info ingress-nginx

URI:

SHA256: 34e999ddc4e1926bbd7f4bdbb5fc40d6c3a5b2ffd711131e4f62e2d24cb2a179

DESCRIPTION:

The official kubectl plugin for ingress-nginx. NAME: ingress-nginxURI: https://github.com/kubernetes/ingress-nginx/releases/download/nginx-0.24.0/kubectl-ingress_nginx-darwin-amd64.tar.gz SHA256: 34e999ddc4e1926bbd7f4bdbb5fc40d6c3a5b2ffd711131e4f62e2d24cb2a179DESCRIPTION:The official kubectl plugin for ingress-nginx. VERSION: 0.24.0 $ kubectl krew install ingress-nginx Updated the local copy of plugin index.

Installing plugin: ingress-nginx

Installed plugin: ingress-nginx

For more information on krew and kubectl plugins in general, checkout Writing kubectl Plugins for Everyone: Develop, Package and Distribute from KubeCon Europe 2019.

Usage

First you must create a minikube cluster and enable the ingress controller. We can also verify that the ingress-nginx pods get generated.

$ minikube start 😄 minikube v1.0.1 on darwin (amd64)

🤹 Downloading Kubernetes v1.14.1 images in the background ...

🔥 Creating virtualbox VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...

📶 "minikube" IP address is 192.168.99.100

🐳 Configuring Docker as the container runtime ...

🐳 Version of container runtime is 18.06.3-ce

⌛ Waiting for image downloads to complete ...

✨ Preparing Kubernetes environment ...

🚜 Pulling images required by Kubernetes v1.14.1 ...

🚀 Launching Kubernetes v1.14.1 using kubeadm ...

⌛ Waiting for pods: apiserver proxy etcd scheduler controller dns

🔑 Configuring cluster permissions ...

🤔 Verifying component health .....

💗 kubectl is now configured to use "minikube"

🏄 Done! Thank you for using minikube! $ minikube addons enable ingress ✅ ingress was successfully enabled $ kubectl get pods -n kube-system | grep ingress nginx-ingress-controller-586cdc477c-74vlb 1/1 Running 0 97s

Now we can troubleshoot by running the ingress-nginx command directly from kubectl.

$ kubectl ingress-nginx --help ....

Available Commands:

backends Inspect the dynamic backend information of an ingress-nginx instance

certs Output the certificate data stored in an ingress-nginx pod

conf Inspect the generated nginx.conf

exec Execute a command inside an ingress-nginx pod

general Inspect the other dynamic ingress-nginx information

help Help about any command

info Show information about the ingress-nginx service

ingresses Provide a short summary of all of the ingress definitions

lint Inspect kubernetes resources for possible issues

logs Get the kubernetes logs for an ingress-nginx pod

ssh ssh into a running ingress-nginx pod

...

Adding Ingress Resources for Testing

Let’s Quickly Create an Application, Service, and Ingress to use in this tutorial.

Deploying an Application

Let’s deploy our application pods(containers), using deployments. More info on deployments can be found here.

$ echo "

apiVersion: extensions/v1beta1

kind: Deployment

metadata:

name: meow

spec:

replicas: 2

selector:

matchLabels:

app: meow

template:

metadata:

labels:

app: meow

spec:

containers:

- name: meow

image: gcr.io/kubernetes-e2e-test-images/echoserver:2.1

ports:

- containerPort: 8080

" | kubectl apply -f - deployment.extensions/meow created

Expose pods via a Service

Here we expose the application on an internal IP of the cluster. For more information on services, see here.

$ echo "

apiVersion: v1

kind: Service

metadata:

name: meow-svc

spec:

ports:

- port: 80

targetPort: 8080

protocol: TCP

name: http

selector:

app: meow

" | kubectl apply -f - service/meow-svc created

Create the Ingress Resource

This allows us to access the service meow-svc via the /meow path. Since we are using minikube and cats.com is our virtual host, so we must pass the host header to access the application.