The connection to the server 127.0.0.1:32768 was refused - did you specify the right host or port?

What is happening?

  1. I’m Using a KinD cluster in Github Action the flow of workflow yaml is:
  2. Creating KinD cluster (Created successfully)
  3. Getting Nodes via kubectl get nodes
NAME                 STATUS   ROLES    AGE   VERSION
kind-control-plane   Ready    master   68s   v1.17.0
  1. Now I’m trying to use the cluster inside my personal Github action bypassing kubeconfig. It is showing connection error:
exit status 1: The connection to the server 127.0.0.1:32768 was refused - did you specify the right host or port?

Did I need to do anything else?

Workflow-yaml

name: Push
on:
  push:
    branches: [ master ]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2

    - name: Creating KinD cluster
      run: |
        GO111MODULE=on 
        curl -Lo ./kind https://github.com/kubernetes sigs/kind/releases/download/v0.7.0/kind-$(uname)-amd64
        chmod +x ./kind
        sudo mv ./kind /usr/local/bin/kind
        kind version
        kind create cluster --loglevel debug
        sleep 60

    - name: Getting Nodes
      run: |
        kubectl get nodes

    - name: Set config
      run: echo ::set-env name=KUBE_CONFIG_DATA::$(base64 -w 0 ~/.kube/config)
  
      #This is the custom Github Action inside which the kubectl command is not running.
    - name: Running Litmus pod delete chaos experiment
      uses: uditgaurav/kubernetes-chaos@v0.1.0

It looks like your action is implemented as a docker container, but you started your kind cluster on the daemon on the VM host. Given the way docker networking is setup I don’t think you are going to be able to see that published port from inside a container. Also, your action will not have access to ~/.kube/config as that is the home path on the VM.

If you run your tests using a bash script or an action implemented in JavaScript it should work.

2 Likes

Yes, for this specific case
We can use kind inside action using
kind get kubeconfig --internal >$HOME/.kube/config
it works for the version 0.7 of kind