Kubernetes Service connection refused Kubernetes Service connection refused kubernetes kubernetes

Kubernetes Service connection refused


By default, kubernetes creates a virtual proxy. You can then access your service after port forwarding it.

kubectl port-forward svc random-generator-svc 5050:5050


That's because of a slight typo in your yaml indent. try this

apiVersion: v1kind: Servicemetadata:  name: random-generator-svc  labels:    app: rand-genspec:  selector:    app: rand-gen  type: NodePort  ports:  - protocol: "TCP"    port: 5050    targetPort: 5050    name: http---apiVersion: apps/v1kind: Deploymentmetadata:  name: random-generator-deployment  labels:    app: rand-genspec:  replicas: 2  selector:    matchLabels:      app: rand-gen  template:    metadata:      labels:        app: rand-gen    spec:      containers:      - name: random-generator-container        image: toky03/random-generator-image:1.2        ports:        - containerPort: 5050

if you only want your app to be exposed inside your cluster, just remove type: NodePort eg:

apiVersion: v1kind: Servicemetadata:  name: random-generator-svc  labels:    app: rand-genspec:  selector:    app: rand-gen  ports:  - protocol: "TCP"    port: 5050    targetPort: 5050    name: http


Try "http://random-generator-svc.default.svc.cluster.local:5050" .You can replace the "default" with the namespace if you are using any.