kubectl error: “The connection to the server localhost:8080 was refused – did you specify the right host or port?”


You want to use the kubectl to get your cluster information but you are getting the following error message

$ kubectl cluster-info
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
The connection to the server localhost:8080 was refused - did you specify the right host or port?


That could happen if you have already setup kubectl before or have used a different environment.

So you will need to first unset the environment variable KUBECONFIG with:


and then use the gcloud client to set your environment again:

$ gcloud container clusters get-credentials your_cluster_name --zone europe-west2-a --project your_project_name

So after this you should be able to use kubectl to get the cluster information

kubeconfig entry generated for your_cluster_name.

$ kubectl cluster-info
Kubernetes master is running at https://xxx.xxx.xxx.xxx
GLBCDefaultBackend is running at https://xxx.xxx.xxx.xxx/api/v1/namespaces/kube-system/services/default-http-backend:http/proxy
Heapster is running at https://xxx.xxx.xxx.xxx/api/v1/namespaces/kube-system/services/heapster/proxy
KubeDNS is running at https://xxx.xxx.xxx.xxx/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://xxx.xxx.xxx.xxx/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy

Change PDF orientation in linux command line


You would like to change the orientation of a PDF file (portrait to landscape) in the linux command line


Use the pdftk program as following (taken from the answer https://unix.stackexchange.com/a/394068)

pdftk portrait.pdfcat 1-endwest output landscape_anti_clockwise.pdf

pdftk portrait.pdf cat 1-endeast output landscape_clockwise.pdf

Automatic emails using bash and sendgrid


You would like to be able to automatically send some emails (ie reports) from a linux server, using a bash script that runs in cronjob, without installing an email server on the linux server.


  • Create an account in Sendgrid and follow the directions for using WebAPI with curl
  • Set up your bash script to use the API key and have a script like the following. If you want to use big or multiple files you will need to use a temporary file for the base64 encoding, as in the example below, as there is a limit in curl.
  • Add your script to crontab
  • curl: (7) Failed to connect to localhost port 80: Connection refused


    You would like to access a host set up with nginx after adding your own vhost configuration file in /etc/nginx/conf.d/myfile.smth, but you get Connection refused.


    Make sure that your nginx configuration file has the .conf extension as /etc/nginx/conf.d/myfile.conf.