Kubernetes can not see my application at the given IP Kubernetes can not see my application at the given IP kubernetes kubernetes

Kubernetes can not see my application at the given IP


Your service specification target all pods with label "app=kubectl-test-189010" which your pod's specification doesn't have.

You need to update pod's metadata so it will match selector from service spec:

    metadata:       name: kubectl-test       app: kubectl-test-189010

Also your service accept connections on port 8000 and then forward it to port 8000 (targetPort) on pod. But pod listen on port 8080 (containerPort). So one of them should be changed to match another - targetPort or containerPort.

You can read more about configuring services in Kubernetes here: https://kubernetes.io/docs/concepts/services-networking/service/


As @Leonid Talalaev mentioned, your selectors in your pod and service aren't in sync. Also, looking at the output for kubectl get services, your app is exposed outside the cluster on NodePort 31592. Did you try accessing the app using this port?

I would also recommend using a Deployment instead of a Pod. Using a Deployment will automatically create the required ReplicaSet and Pod(s) when you create the Deployment with kubectl.

I'm not sure what your desired NodePort is, but if you want to expose your app outside the cluster on port 32000(for example), you could use the configs below. Then you should be able to access your app with http://<CLUSTER_IP>:32000/

# deployment.ymlapiVersion: extensions/v1beta1kind: Deploymentmetadata:  name: kubectl-test  labels:    app: kubectl-testspec:  replicas: 3  strategy: {}  template:    metadata:      labels:        app: kubectl-test    spec:      containers:      - image: gcr.io/[my-name]/node-app:0.0.1        name: kubectl-test        ports:        - containerPort: 8080        resources: {}      restartPolicy: Alwaysstatus: {}# service.ymlkind: Servicemetadata:    name: kubectl-test-node-app     labels:    app: kubectl-testspec:  ports:    - protocol: TCP      name: "8080"      port: 8080      targetPort: 8080      nodePort: 32000  selector:    app: kubectl-test  type: LoadBalancer  sessionAffinity: None  externalTrafficPolicy: Clusterstatus:   loadBalancer: {}

kubectl create -f deployment.yml
kubectl create -f service.yml


For starters, make sure you know what you want to accomplish. You say service and deployment, but your files refer to Service and Pod.

Deployment is an object, that will create ReplicaSets and scale them so that they result with a particular group of underlying Pods launched in cluster. Taken from Deployments metadata, they will have some labels. These labels are what Service will match it's selector against (labels&selectors). I do assume you do want to use Deployment, to leverage stuff like rolling updates (it's generaly very hard to update Pod in many cases, and you end up deleting and recreating it manualy) or scaling.

With that assumption, you need Deployment (or Pod if you really want to go the "manual" way), that has something like folowing

metadata:  labels:    app: myappname

followed by Service that has a selector defined similarly

selector:  app: myappname

that should be enough for you to have a working setup, and you should see your service will now have active endpoints (assuming your pods are launched and in Ready state.

Also, if you want to contain version in your labels, so that you can ie. target particular pod version with a service, or maybe use it for another reason like pod affinity, you should split it into two labels like

metadata:  labels:    app: myappname    ver: v12