netkat

package module
v0.0.0-...-3548c0f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2019 License: Apache-2.0 Imports: 25 Imported by: 0

README

netkat

Build Status codecov.io Code Coverage Go Report Card Release GoDoc

CLI for troubleshooting kubernetes networking issues.

Getting Started

Build from source:

  • Requires Go 1.13 and dep package management
git clone git@github.com:stevenayers/netkat.git
cd netkat
go build
go build cmd/main.go
mv ./main /usr/local/bin/netkat

For help:

$ netkat -h

Example Usage:

$ netkat grafana.digital.foobar.com -context kops-dev -config ~/.kube/config
$ netkat pod/grafana-fb86ad62c-f63x9:3000 -context kops-dev -config ~/.kube/config
=== RUN   CheckKubernetesRouteFromHost
host: grafana.digital.foobar.com
port: 80
path: /
ip address: 34.89.100.1
 -> ingress: grafana-ingress
    namespace: metrics
    path: /
    ip address: 34.89.100.1
    -> service: grafana-service
       namespace: metrics
       app selector: grafana-app
       external IP: 34.89.100.1
       internal IP: 10.44.0.1
       mapping: http (80) -> 3000
       -> pod: grafana-fb86ad62c-p72v8
          namespace: metrics
          app: grafana-app
          container: grafana
          port: 3000
       -> pod: grafana-fb86ad62c-lg92a
          namespace: metrics
          app: grafana-app
          container: grafana
          port: 3000
       -> pod: grafana-fb86ad62c-f63x9
          namespace: metrics
          app: grafana-app
          container: grafana
          port: 3000
--- PASS: CheckKubernetesRouteFromHost
=== PASS: (1/1)
    --- CheckKubernetesRouteFromHost
=== FAIL: (0/1)

Under development, current version will only print out the route when config is setup correctly. Incorrect configuration just throws an error and prints out nothing. This needs to be implemented properly.

  • Checks ownership of DNS records (to be implemented)
  • Checks external DNS logs (to be implemented)
  • Matches A record against ingress/service
  • Checks service/ingress config
  • Checks ports mappings
  • Checks port is open on pod
  • Checks LB rules on cloud provider side (to be implemented)
  • Checks LoadBalancerSourceRanges (to be implemented)

What Done Looks Like

End-to-end Scenarios

local -> pod_name:port
local -> fqdn:port
local -> http(s)://url/path
local -> http(s)://url:port/path
Check Name Description Done
CheckKubernetesRouteFromHost Takes the host:port info and matches it to ingress or/then service then pod. x
CheckStatusPod Checks pod status is running x
CheckListeningPod Portforwards directly to pod and checks connection x
CheckKubernetesRouteFromPod Takes pod:port and maps backwards to a hostname then checks the host configuration. x
CheckKubernetesRouteFromInternalHost Takes the host:port info and matches it to ingress or/then service then pod but for intra-cluster situations.
CheckKubernetesRoutePodToPod Takes pod:port and maps to pod:port
CheckStatusNginxIngress Checks nginx-ingress is healthy.
CheckStatusTraefikIngress Checks traefik ingress is healthy.
CheckStatusKubeDns Checks kube-dns is healthy.
CheckSourceRangesIngress Checks any source range annotations on ingress against originating IP.
CheckSourceRangesService Checks any source range annotations on service against originating IP.
CheckInboundRulesLB Checks originating IP against inbound rules for Load Balancer.
CheckInboundRulesLBAzure hecks originating IP against inbound rules for Load Balancer.
CheckInboundRulesLBAWS Checks originating IP against inbound rules for Load Balancer.
CheckDnsOwnershipGCP
CheckDnsOWnershipAzure
CheckDnsOwnershipAWS
CheckDnsInternalPodToPod

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger log.Logger

Functions

func InitLogger

func InitLogger(writer io.Writer, logLevel string)

InitJsonLogger function initiates a structured JSON logger, taking in the specified log level for what is displayed at runtime.

func PrintCheckHeader

func PrintCheckHeader()

func PrintCheckResults

func PrintCheckResults(ch *Checker)

func PrintHost

func PrintHost(t *Target)

func PrintIngressPath

func PrintIngressPath(i *IngressPath, indent int)

func PrintPodPort

func PrintPodPort(p *PodPort, indent int)

func PrintServicePort

func PrintServicePort(s *ServicePort, indent int)

Types

type Check

type Check struct {
	Name     string
	Priority int
}

type Checker

type Checker struct {
	Target               *Target
	KubernetesRoute      *KubernetesRoute
	KubernetesComponents *KubernetesComponents
	Client               Client
	RequiredChecks       []string
	PassedChecks         []string
	FailedChecks         []string
}

func (*Checker) CheckKubernetesRouteFromHost

func (ch *Checker) CheckKubernetesRouteFromHost()

func (*Checker) CheckListeningPod

func (ch *Checker) CheckListeningPod()

func (*Checker) CheckStatusPod

func (ch *Checker) CheckStatusPod()

func (*Checker) FailCheck

func (ch *Checker) FailCheck()

func (*Checker) InitChecks

func (ch *Checker) InitChecks()

func (*Checker) ParseTarget

func (ch *Checker) ParseTarget(path string) (err error)

func (*Checker) PassCheck

func (ch *Checker) PassCheck()

func (*Checker) RunChecks

func (ch *Checker) RunChecks()

type Client

type Client struct {
	*kubernetes.Clientset
	Config *rest.Config
}

func InitClient

func InitClient(context string, kubeConfig string) (k8sClient Client)

func (*Client) GetComponents

func (c *Client) GetComponents() (components *KubernetesComponents)

func (*Client) GetIngresses

func (c *Client) GetIngresses() (apiIngresses *v1beta1.IngressList)

func (*Client) GetPods

func (c *Client) GetPods() (apiPods *v1.PodList)

func (*Client) GetServices

func (c *Client) GetServices() (apiServices *v1.ServiceList)

func (*Client) IsPodListening

func (c *Client) IsPodListening(p *PodPort) (result bool)

type IngressPath

type IngressPath struct {
	Host           string `json:"host,omitempty"`
	IpAddress      net.IP `json:"ipAddress,omitempty"`
	Namespace      string `json:"namespace,omitempty"`
	IngressName    string `json:"name,omitempty"`
	Path           string `json:"path,omitempty"`
	ServiceName    string `json:"serviceName,omitempty"`
	ServiceIntPort int32  `json:"servicePort,omitempty"`
	ServiceStrPort string `json:"servicePort,omitempty"`
	Service        []*ServicePort
}

func IngressesToIngressPaths

func IngressesToIngressPaths(apiIngresses *v1beta1.IngressList) (ingressPaths []*IngressPath)

type KubernetesComponents

type KubernetesComponents struct {
	IngressPaths []*IngressPath
	ServicePorts []*ServicePort
	PodPorts     []*PodPort
}

func (*KubernetesComponents) FindIngressPathForHost

func (co *KubernetesComponents) FindIngressPathForHost(t *Target) (ingressPath *IngressPath, err error)

func (*KubernetesComponents) FindIngressPathForServicePort

func (co *KubernetesComponents) FindIngressPathForServicePort(s *ServicePort) (ingressPath *IngressPath, err error)

func (*KubernetesComponents) FindPodPort

func (co *KubernetesComponents) FindPodPort(n string) (podPort *PodPort, err error)

func (*KubernetesComponents) FindPodPortForServicePort

func (co *KubernetesComponents) FindPodPortForServicePort(s *ServicePort) (podPorts []*PodPort, err error)

func (*KubernetesComponents) FindServicePortForHost

func (co *KubernetesComponents) FindServicePortForHost(t *Target) (servicePort *ServicePort, err error)

func (*KubernetesComponents) FindServicePortForIngressPath

func (co *KubernetesComponents) FindServicePortForIngressPath(i *IngressPath) (servicePort *ServicePort, err error)

func (*KubernetesComponents) FindServicePortForPodPort

func (co *KubernetesComponents) FindServicePortForPodPort(p *PodPort) (servicePort *ServicePort, err error)

type KubernetesRoute

type KubernetesRoute struct {
	Ingress *IngressPath
	Service *ServicePort
	Pods    []*PodPort
}

type PodPort

type PodPort struct {
	PodName        string `json:"name,omitempty"`
	Namespace      string `json:"namespace,omitempty"`
	App            string
	ContainerImage string `json:"image,omitempty"`
	ContainerName  string `json:"name,omitempty"`
	PortName       string `json:"name,omitempty"`
	HostPort       int32  `json:"hostPort,omitempty"`
	ContainerPort  int32  `json:"containerPort,omitempty"`
	Protocol       string `json:"protocol,omitempty"`
	HostIP         net.IP `json:"hostIP,omitempty"`
	ServicePort    ServicePort
	PodStatus      string `json:"status,omitempty"`
}

func PodsToPodPorts

func PodsToPodPorts(apiPods *v1.PodList) (podPorts []*PodPort)

type ServicePort

type ServicePort struct {
	Type           string `json:"type,omitempty"`
	ClusterIP      net.IP `json:"clusterIP,omitempty"`
	ServiceName    string `json:"name,omitempty"`
	Namespace      string `json:"namespace,omitempty"`
	ExternalIP     net.IP
	AppSelector    string
	Host           string
	SourcePortName string `json:"name,omitempty"`
	Protocol       string `json:"protocol,omitempty"`
	SourcePort     int32  `json:"port,omitempty"`
	NodePort       int32  `json:"nodePort,omitempty"`
	TargetPort     int32  `json:"targetPort,omitempty"`
	TargetPortName string `json:"targetPort,omitempty"`
	IngressPath    IngressPath
	PodPort        []*PodPort
}

func ServicesToServicePorts

func ServicesToServicePorts(apiServices *v1.ServiceList) (servicePorts []*ServicePort)

type Target

type Target struct {
	Host      string
	Path      string
	Port      int32
	IpAddress net.IP
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL