How to get list of NGINX VirtualServer and VirtualServerRoute in K8S?

6/12/2020

Below is the example to add Virtual Server and VirtualServerRoute in kubernetes-ingress.

<!-- begin snippet: js hide: false console: true babel: false --><!-- language: lang-html -->
apiVersion: k8s.nginx.org/v1
kind: VirtualServer
metadata:
  name: virtualserver
spec:
  host: localhost
  routes:
  - path: /
    route: virtualserverroute
---
apiVersion: k8s.nginx.org/v1
kind: VirtualServerRoute
metadata:
  name: virtualserverroute
spec:
  host: localhost
  upstreams:
  - name: proxy
    service: proxy
    port: 80
  - name: webserverv1
    service: webserverv1
    port: 80
  - name: webserverv2
    service: webserverv2
    port: 80
  subroutes:
  - path: /webserverv1
    action:
      pass: webserverv1
  - path: /webserverv2
    action:
      pass: webserverv2
  - path: /
    action:
      pass: proxy
<!-- end snippet -->

Anyone knows How to get list of NGINX VirtualServer and VirtualServerRoute for that ingress in K8S?

-- Dhaval Thakkar
kubernetes
kubernetes-ingress
nginx
nginx-ingress

1 Answer

6/16/2020

Anyone knows How to get list of NGINX VirtualServer and VirtualServerRoute for that ingress in K8S?

You can list resources like VirtualServer and VirtualServerRoute by invoking below command:

  • $ kubectl get VirtualServer or kubectl get vs
  • $ kubectl get VirtualServerRoute or kubectl get vsr

Please have in mind that above resources are Custom Resources and they should be added to Kubernetes.


VirtualServer as well as VirtualServerRoute are connected specifically to the Nginx Ingress Controller created by NginxInc.

Github link: Nginxinc: Kubernetes Ingress

As said on the Github site:

Note: this project is different from the NGINX Ingress controller in kubernetes/ingress-nginx repo. See this doc to find out about the key differences.

<cite> Github.com: Nginxinc: Kubernetes Ingress </cite>

To be able to create:

  • VirtualServer
  • VirtualServerRoute

resources you will need to follow this documentation.

If you are using the manifests with git please make sure that you apply following manifests:

$ kubectl apply -f common/vs-definition.yaml
$ kubectl apply -f common/vsr-definition.yaml
$ kubectl apply -f common/ts-definition.yaml

As they are CRD's for above resources.

After successful provisioning of nginx-ingress you should be able to create VirtualServer and VirtualServerRoute and get more information about them with:

  • kubectl describe vs
  • kubectl describe vsr
-- Dawid Kruk
Source: StackOverflow