My Kubernetes cluster is on AWS
. I have setup the context using commands to connect to the Kubernetes cluster but still I am getting the following error:
The connection to the server localhost:8080 was refused - did you specify the right host or port?
Please note that kubectl and aws-iam-authenticator are installed and the config file is located in the home directory of the user inside .kube
folder.
I have verified by running the command that aws sts get-caller-identity that I am connected to the AWS via cli.
Following are the configuration steps that I have taken:
export CLUSTER=abcd.com
export API_ENDPOINT=abcd.com
export TEAM_NAMESPACE=abcd
kubectl config set-cluster $CLUSTER --server=$API_ENDPOINT
kubectl config set-credentials $CLUSTER \
--exec-api-version="client.authentication.k8s.io/v1beta1" \
--exec-command="aws-iam-authenticator" \
--exec-arg="token" \
--exec-arg="-i" \
--exec-arg="$CLUSTER"
kubectl config set-context $CLUSTER --cluster=$CLUSTER --namespace=$TEAM_NAMESPACE --user=$CLUSTER
kubectl config use-context $CLUSTER
Please share suggestions to solve this issue.
I had a look at the config file by using the command "kubectl config view --minify" and found that somehow the server field was empty. I edited the file using vi editor and set the API server value manually there. It resolved the issue.