Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubectl port-forward not working on EC2 instance

For some reason, the kubectl port-forward is not working for me.

Here is the deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: doc-deployment
  labels:
    app: doc
spec:
  replicas: 1
  selector:
    matchLabels:
      app: doc
  template:
    metadata:
      labels:
        app: doc
    spec:
      containers:
        - name: doc-nginx
          image: "doc-server:stable"
          ports:
          - containerPort: 80
          imagePullPolicy: Always
      imagePullSecrets:
        - name: regcred

Currently it is deployed on Minikube which is hosted on EC2 instance where all necessary ports are open.

[centos@doc ~]$ kubectl get pods -o wide
NAME                                 READY   STATUS    RESTARTS   AGE   IP           NODE       NOMINATED NODE   READINESS GATES
doc-deployment-788b6c4d8d-pvwcc   1/1     Running   0          38h   172.18.0.4   minikube   <none>           <none>

[centos@doc ~]$ kubectl get deploy -o wide
NAME                READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS     IMAGES                                                           SELECTOR
doc-deployment   1/1     1            1           38h   doc-nginx   doc-server:stable   app=doc

[centos@doc ~]$ kubectl get svc -o wide
NAME                TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE   SELECTOR
kubernetes          ClusterIP      10.96.0.1        <none>        443/TCP        38h   <none>
doc-deployment   LoadBalancer   10.105.129.111   <pending>     80:30766/TCP   38h   app=doc

[centos@doc ~]$ minikube ip
172.17.0.4

[centos@doc ~]$ minikube service doc-deployment --url
http://172.17.0.4:30766

[centos@doc ~]$ curl http://172.17.0.4:30766
<!DOCTYPE html>
<meta charset="utf-8">
<script>location="doc/index.html"</script>
<meta http-equiv="refresh" content="0; url=doc/index.html">
<meta name="robots" content="noindex">
<title>Redirect Notice</title>
<h1>Redirect Notice</h1>
<p>The page you requested has been relocated to <a href="doc/index.html">doc/index.html</a>.</p>

[centos@scdpsbx069-euc1 ~]$ kubectl port-forward --address 0.0.0.0 pods/doc-deployment-788b6c4d8d-pvwcc 5000:80
Forwarding from 0.0.0.0:5000 -> 80

and when I try accessing it on browser, it is not reachable.

enter image description here

Am I missing something here ?. Please advice.

like image 608
Ashfaq Avatar asked Mar 03 '23 04:03

Ashfaq


1 Answers

Try the below command

kubectl port-forward svc/doc-deployment --address 0.0.0.0 5000:80
like image 162
P Ekambaram Avatar answered Mar 05 '23 18:03

P Ekambaram