Cannot Access IP and PORT on kubernetes minikube

Viewed 2495

I have created web deployment and service on kubernetes When i list the service with $ kubectl get service command to list IP and Port to access the webpage but when i try to access it the site cant be reached. It seem if kubernetes on minikube didnt pull image from docker hub..

Here my example script.. I use Kubernetes v1.19.2 with default driver Docker 19.03.8

  1. $ kubectl create -f web-pets.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pets
      service: web
  template:
    metadata:
      labels:
        app: pets
        service: web
    spec:
      containers:
      - image: nginx:alpine-1.19.2
        name: web
        ports:
        - containerPort: 80
          protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  type: NodePort
  ports:
  - port: 80
    protocol: TCP
  selector:
    app: pets
    service: web
  1. Output create web-pets.yaml
$ kubectl create -f web-pets.yaml
deployment.apps/web created
service/web created
  1. Output $ kubectl get service
$ kubectl get service
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP        11h
web          NodePort    10.110.107.234   <none>        80:30100/TCP   41s
  1. Output $ kubectl get service web
Name:                     web
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=pets,service=web
Type:                     NodePort
IP:                       10.109.10.68
Port:                     <unset>  3000/TCP
TargetPort:               3000/TCP
NodePort:                 <unset>  31830/TCP
Endpoints:                <none>
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>
  1. When list all docker images no nginx image
$ docker images
REPOSITORY                     TAG                 IMAGE ID      CREATED       SIZE
kicbase/stable                 v0.0.12-snapshot3   25ac91b9c8d7  4 weeks ago   952MB
gcr.io/k8s-minikube/kicbase    v0.0.12-snapshot3   25ac91b9c8d7  4 weeks ago   952MB
  1. Deploy web description
$ kubectl describe deploy web
Name:                   web
Namespace:              default
CreationTimestamp:      Thu, 24 Sep 2020 17:25:42 +0700
Labels:                 <none>
Annotations:            <none>
Selector:               app=pets,service=web
Replicas:               1 desired | 0 updated | 0 total | 0 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=pets
           service=web
  Containers:
   web:
    Image:        nginx:alpine-1.19.2
    Port:         3000/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
OldReplicaSets:   <none>
NewReplicaSet:    <none>
Events:           <none>
  1. $ kubectl get pods
$ kubectl get pods
No resources found in default namespace.
  1. $ kubectl get events
LAST SEEN   TYPE     REASON                    OBJECT          MESSAGE
7m13s       Normal   Starting                  node/minikube   Starting kubelet.
7m11s       Normal   NodeHasSufficientMemory   node/minikube   Node minikube status is now: NodeHasSufficientMemory
7m11s       Normal   NodeHasNoDiskPressure     node/minikube   Node minikube status is now: NodeHasNoDiskPressure
7m11s       Normal   NodeHasSufficientPID      node/minikube   Node minikube status is now: NodeHasSufficientPID
7m12s       Normal   NodeAllocatableEnforced   node/minikube   Updated Node Allocatable limit across pods
6m28s       Normal   Starting                  node/minikube   Starting kube-proxy.
1 Answers

Nginx listens on port 80. Hence you need to use port 80 instead of port 3000 in the deployment and service. From the docs you should be able to access it using minikube service web

Related