unable to access application from kubernetes

11/2/2019

I have created a simple php application trying to access from kubernetes cluster but I am unable access the application

my deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: phpdeployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: phpapp
  template:
    metadata:
      labels:
        app: phpapp
    spec:
      containers:
      - image: rajendar38/myhtmlapp
        name: myhtmlapp
        ports:
        - containerPort: 80

my service.yml

apiVersion: v1
kind: Service
metadata:
  name: php-service
spec:
  selector:
    app: myhtmlapp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
      nodePort: 31000
  type: NodePort

rajendar@HP-EliteBook:~/Desktop/work$ kubectl get services
NAME          TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes    ClusterIP   10.96.0.1        <none>        443/TCP        26h
my-service    ClusterIP   10.102.235.244   <none>        4000/TCP       24h
php-service   NodePort    10.110.73.30     <none>        80:31000/TCP   22m

I am using minikube for this application when I am trying to connect to http:127.0.0.1:31000/test.html I unable to connect to application

Thanks

Rajendar

-- Rajendar Talatam
docker
kubectl
kubernetes
minikube

3 Answers

11/6/2019

The target port and port are same 80 therefore the services is using port 80 for both try

    port: 8000
    targetPort: 80
-- Muhammad Ibtihaj Naeem
Source: StackOverflow

11/20/2019

As say @Thomas, you must find the IP of the VM with:

minikube ip

and after launch the service with this IP and the port 31000, in your case.

-- javifernandezr
Source: StackOverflow

11/2/2019

Minikube is using a virtual machine to provide the single node cluster. When exposing a NodePort service it is local from the perspective of the VM, which is usually not the same as your local machine.

Use minikube ip to determine the IP of the machine and use that IP instead of localhost or 127.0.0.1 to access NodePort services on the minikube cluster.

-- Thomas
Source: StackOverflow