kubectl Networking commands

57 commands in 6 groups: GatewayClass, Gateway API, HTTPRoutes, Ingress, IngressClass, Network Policies. Click or tap any command to copy it. Official documentation: kubernetes.io.

Open in the interactive cheat sheet search, stars and every other section

GatewayClass

Manage GatewayClass resources that define which controller implements a Gateway.
kubectl annotate gatewayclass <name> <key>=<value>
Add or update an annotation
kubectl delete gatewayclass <name>
Delete a GatewayClass
kubectl describe gatewayclass <name>
GatewayClass details and controller
kubectl get gatewayclass
List all GatewayClasses (cluster-wide)
kubectl get gatewayclass -o wide
Adds the Description column
kubectl get gatewayclass <name> -o jsonpath='{.status.conditions}'
Show acceptance conditions
kubectl get gatewayclass <name> -o yaml
Get GatewayClass manifest as YAML

Gateway API

Manage Gateways that define the entry points for cluster traffic in the Gateway API model.
kubectl annotate gateway <name> -n <namespace> <key>=<value>
Add or update an annotation
kubectl apply -f gateway.yaml
Apply Gateway from manifest
kubectl delete gateway <name> -n <namespace>
Delete a Gateway
kubectl describe gateway <name> -n <namespace>
Gateway listeners, status, and attached routes
kubectl edit gateway <name> -n <namespace>
Edit Gateway in $EDITOR
kubectl get gateways
List Gateways with class, address and programmed status
kubectl get gateways -A
All Gateways across namespaces
kubectl get gateways -n <namespace>
Gateways in a namespace
kubectl get gateway <name> -n <namespace> -o jsonpath='{.status.addresses}'
Show assigned addresses
kubectl get gateway <name> -n <namespace> -o yaml
Get Gateway manifest as YAML

HTTPRoutes

Manage HTTPRoutes and ReferenceGrants for routing traffic to services across namespaces.
kubectl apply -f httproute.yaml
Apply HTTPRoute from manifest
kubectl apply -f referencegrant.yaml
Apply ReferenceGrant from manifest
kubectl delete httproute <name> -n <namespace>
Delete an HTTPRoute
kubectl delete referencegrant <name> -n <namespace>
Delete a ReferenceGrant
kubectl describe httproute <name> -n <namespace>
HTTPRoute rules, parent refs, and status
kubectl describe referencegrant <name> -n <namespace>
ReferenceGrant allowed cross-namespace refs
kubectl edit httproute <name> -n <namespace>
Edit HTTPRoute in $EDITOR
kubectl get httproutes
List HTTPRoutes with hostnames
kubectl get httproutes -A
All HTTPRoutes across namespaces
kubectl get httproutes -n <namespace>
HTTPRoutes in a namespace
kubectl get referencegrants -n <namespace>
ReferenceGrants for cross-namespace routing
kubectl get httproute <name> -n <namespace> -o jsonpath='{.spec.rules}'
Show routing rules as JSON
kubectl get httproute <name> -n <namespace> -o yaml
Get HTTPRoute manifest as YAML

Ingress

Manage HTTP/HTTPS routing rules to expose services externally via an ingress controller.
kubectl annotate ingress <name> <key>-
Remove an annotation
kubectl annotate ingress <name> <key>=<value>
Add or update an annotation
kubectl apply -f ingress.yaml
Apply Ingress from manifest
kubectl delete ingress <name>
Delete an Ingress
kubectl describe ingress <name>
Ingress rules and backend details
kubectl describe ingress <name> -n <namespace>
Ingress details in a specific namespace
kubectl edit ingress <name>
Edit Ingress in $EDITOR
kubectl get ingress
List Ingresses in current namespace
kubectl get ing -A
All Ingresses across namespaces
kubectl get ingress -n <namespace>
Ingresses in a specific namespace
kubectl get ingress <name> -o jsonpath='{.spec.rules}'
Show routing rules as JSON
kubectl get ingress <name> -o yaml
Get Ingress manifest as YAML
kubectl patch ingress <name> --type=merge -p '{"spec":{"ingressClassName":"<class>"}}'
Set IngressClass on an existing Ingress

IngressClass

Manage IngressClass resources that define which controller handles a given Ingress.
kubectl annotate ingressclass <name> ingressclass.kubernetes.io/is-default-class-
Remove default-class annotation
kubectl annotate ingressclass <name> ingressclass.kubernetes.io/is-default-class=true --overwrite
Mark IngressClass as cluster default
kubectl delete ingressclass <name>
Delete an IngressClass
kubectl describe ingressclass <name>
IngressClass details and controller
kubectl get ingressclass
List all IngressClasses
kubectl get ingressclass <name> -o yaml
Get IngressClass manifest as YAML

Network Policies

Define rules to control ingress and egress traffic between pods and namespaces.
kubectl apply -f netpol.yaml
Apply NetworkPolicy from manifest
kubectl delete networkpolicy <name>
Delete a NetworkPolicy
kubectl describe networkpolicy <name>
Policy details, pod/namespace selectors
kubectl edit networkpolicy <name>
Edit NetworkPolicy in $EDITOR
kubectl get networkpolicies
List NetworkPolicies
kubectl get netpol -A
All NetworkPolicies across namespaces
kubectl get netpol -n <namespace>
NetworkPolicies in a namespace
kubectl get networkpolicy <name> -o yaml
Get NetworkPolicy manifest as YAML