Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

408
Views
How to let Kubernetes pod run a local script

I want to run a local script within Kubernetes pod and then set the output result to a linux variable

Here is what I tried:

# if I directly run -c "netstat -pnt |grep ssh", I get output assigned to $result:

cat check_tcp_conn.sh 
#!/bin/bash
result=$(kubectl exec -ti <pod_name> -- /bin/bash -c "netstat -pnt |grep ssh")
echo "result is $result"

What I want is something like this:

#script to be called:
cat netstat_tcp_conn.sh
#!/bin/bash
netstat -pnt |grep ssh

#script to call netstat_tcp_conn.sh:
cat check_tcp_conn.sh 
#!/bin/bash
result=$(kubectl exec -ti <pod_name> -- 
/bin/bash -c "./netstat_tcp_conn.sh)
echo "result is $result

the result showed result is /bin/bash: ./netstat_tcp_conn.sh: No such file or directory.

How can I let Kubernetes pod execute netstat_tcp_conn.sh which is at my local machine?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use following command to execute your script in your pod:

kubectl exec POD -- /bin/sh -c "`cat netstat_tcp_conn.sh`"
over 4 years ago · Santiago Trujillo Report

0

You can copy local files into pod using kubectl command like kubectl cp /tmp/foo :/tmp/
Then you can change its permission and make it executable and run it using kubectl exec.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!