Coder Social home page Coder Social logo

segmentio / kubectl-curl Goto Github PK

View Code? Open in Web Editor NEW
176.0 8.0 15.0 77 KB

Kubectl plugin to run curl commands against kubernetes pods

License: MIT License

Go 100.00%
kubectl kubectl-plugins kubectl-plugin kubectl-command kubectl-commands curl golang kubernetes

kubectl-curl's Introduction

kubectl-curl

Kubectl plugin to run curl commands against kubernetes pods

Motivation

Sending http requests to kubernetes pods is unnecessarily complicated, this plugin makes it easy.

The plugin creates a port forwarding from the local network to the kubernetes pod that was selected to receive the request, then instantiate a curl command by rewriting the URL to connect to the forwarded local port, and passing all curl options that were given on the command line.

Installation

If $GOPATH/bin is in the PATH, the plugin can be installed with:

$ go install github.com/segmentio/kubectl-curl@latest

If it was installed properly, it will be visibile when listing kubectl plugins:

$ kubectl plugin list
The following compatible plugins are available:

/.../kubectl-curl

Usage

kubectl curl [options] URL [container]
  • In the URL, the host part must be the name of the pod to send the request to.
  • If no port number is specified, the request will be sent to a http port.
  • If there are multiple containers with a http port, the name of the container to send to the request to must be specified after the URL.

Examples

This section records common use cases for this kubectl plugin.

Collecting profiles of Go programs

$ kubectl curl "http://{pod}/debug/pprof/profile?debug=1&seconds=10" > ./profile
$ go tool pprof -http :6060 ./profile

Retrieving prometheus metrics

$ kubectl curl http://{pod}/metrics
...

kubectl-curl's People

Contributors

achille-roussel avatar bartleyg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kubectl-curl's Issues

Unable to use the --user option

When I try to use the --user username:password option, I consistently get this error message:

  • ERROR: auth info "username:password" does not exist
    Error: exit status 1

Any chance this repo is still being watched?

Cannot use -X argument

While trying to use -X POST, the plugin complains such argument is invalid (set URL and CONTAINER to some valid values). I have seen a similar behavior while using -d.

$ kubectl curl -i -X POST $URL $CONTAINER
curl: option --request=POST: is unknown
curl: try 'curl --help' or 'curl --manual' for more information

Reproduced in both macOS and Ubuntu 20.04. Details below.

MacOS environment:

$ curl --version
curl 7.77.0 (x86_64-apple-darwin21.0) libcurl/7.77.0 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.42.0
Release-Date: 2021-05-26
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL UnixSockets

$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.2", GitCommit:"f5743093fd1c663cb0cbc89748f730662345d44d", GitTreeState:"clean", BuildDate:"2020-09-16T21:51:49Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"darwin/amd64"}

$ sw_vers
ProductName:	macOS
ProductVersion:	12.0.1
BuildVersion:	21A559

Linux environment:

$ curl --version
curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3
Release-Date: 2020-01-08
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets

$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.1", GitCommit:"86ec240af8cbd1b60bcc4c03c20da9b98005b92e", GitTreeState:"clean", BuildDate:"2021-12-16T11:41:01Z", GoVersion:"go1.17.5", Compiler:"gc", Platform:"linux/amd64"}

$ lsb_release -a
LSB Version:	core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.3 LTS
Release:	20.04
Codename:	focal

Distribute kubectl plugin via Krew

Would it be possible to distribute this plugin via Krew? I believe this would help with the discovery of this plugin & simplifying the installation process ๐Ÿ™‚

BUG: invalid character "{" in host name

I installed kubectl-curl from the README and ran into an error.

Install:

$ go install github.com/segmentio/kubectl-curl@latest 
go: downloading github.com/segmentio/kubectl-curl v0.1.5

Error:

$ kubectl curl http://{pod}/metrics
* ERROR: malformed URL: parse "http://{pod}/metrics": invalid character "{" in host name

using with go-teleport fails on first char missing

Hi! We use go-teleport installed at say tele.host.com. Using kubectl curl I get this:

m ~/D/  kubectl curl -vvv --debug "http://{podname}:3000/healthz"
* 2022/05/15 21:46:39 kubectl get -n default pod/{podname}
* 2022/05/15 21:46:41 forwarding local port 14187 to port 3000 of
* 2022/05/15 21:46:41 waiting for port fowarding to be established
* 2022/05/15 21:46:41 error upgrading connection: error sending request: Post "https://ele.host.com:3026/api/v1/namespaces/default/pods/zenith-console-7c64d658bd-mqvdv/portforward": dial tcp: lookup ele.host.com: no such host
^C* 2022/05/15 21:47:00 shutting down port forwarder
* 2022/05/15 21:47:00 waiting for port forwarder to stop

and it hangs forever. There is obviously no ele.host.com. Cause it's tele.host.com. Can't say for sure, this is not a go-teleport bug, sorry.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.