Search code examples
nginxkuberneteskubectlkube-controller-manager

Kubernetes deployment fails


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.


Solution

  • 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