<p>I'm on an ec2 instance trying to get my cluster created. I have kubectl already installed and here are my services and workloads yaml files</p>
<p>services.yaml</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: stockapi-webapp

spec:
  selector:
    app: stockapi

  ports:
    - name: http
      port: 80

  type: LoadBalancer
</code></pre>
<p>workloads.yaml</p>
<pre><code>apiVersion: v1
kind: Deployment
metadata:
  name: stockapi
spec:
  selector:
    matchLabels:
      app: stockapi
  replicas: 1
  template: # template for the pods
    metadata:
      labels:
        app: stockapi
    spec:
      containers:
      - name: stock-api
        image: public.ecr.aws/u1c1h9j4/stock-api:latest
</code></pre>
<p>When I try to run</p>
<pre><code>kubectl apply -f workloads.yaml
</code></pre>
<p>I get this as an error</p>
<pre><code>The connection to the server localhost:8080 was refused - did you specify the right host or port?
</code></pre>
<p>I also tried changing the port in my services.yaml to 8080 and that didn't fix it either</p>

MP32
<p>This error comes when you don't have <code>~/.kube/config</code> file present or configured correctly on the client / where you run the <code>kubectl</code> command.</p>
<p>kubectl reads the clusterinfo and which port to connect to from the  <code>~/.kube/config</code> file.</p>
<p>if you are using eks here's how you can create <code>config</code> file
<a href="https://docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html" rel="noreferrer">aws eks create kubeconfig file</a></p>
