Kubernetes deployment fails

9/9/2019

I have Pod and Service ymal files in my system. I want to run these two using kubectl create -f <file> and connect from outside browser to test connectivity.Here what I have followed.

My Pod :

apiVersion: v1
kind: Pod
metadata:
  name: client-nginx
  labels:
    component: web
spec:
  containers:
    - name: client
      image: nginx 
      ports:
        - containerPort: 3000

My Services file :

apiVersion: v1
kind: Service
metadata:
    name: client-nginx-port
spec:
  type: NodePort
  ports:
    - port: 3050
      targetPort: 3000
      nodePort: 31616
  selector:
    component: web

I used kubectl create -f my_pod.yaml and then kubectl get pods shows my pod client-nginx

And then kubectl create -f my_service.yaml, No errors here and then shows all the services.

When I try to curl to service, it gives

curl: (7) Failed to connect to 192.168.0.10 port 31616: Connection refused.

kubectl get deployments doesnt show my pod. Do I have to deploy it? I am a bit confused. If I use instructions given here, I can deploynginxsuccessfully and access from outside browsers.

I used instructions given here to test this.

-- Sachith Muhandiram
kube-controller-manager
kubectl
kubernetes
nginx

2 Answers

9/9/2019

You missed selector name to be given to pod yaml which will be picked by service where you have mentioned the selector as component

Use this in pod yaml

apiVersion: v1
kind: Pod
metadata:
  name: client-nginx
  labels:
    component: web
spec:
  selector:
    component: nginx
  containers:
    - name: client
      image: nginx 
      ports:
        - containerPort: 3000

Useful links:

https://kubernetes.io/docs/concepts/services-networking/service/ https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/

-- Prateek Sen
Source: StackOverflow

9/9/2019

Try with this service:

apiVersion: v1
kind: Service
metadata:
    name: client-nginx-port
spec:
  type: NodePort
  ports:
    - port: 3050
      targetPort: 80
      nodePort: 31616
  selector:
    component: web
-- FL3SH
Source: StackOverflow