Home > Enterprise >  kubernetes nginx deployment ERR_CONNECTION_REFUSED
kubernetes nginx deployment ERR_CONNECTION_REFUSED

Time:03-04

I use minikube to deploy example nginx image.
I want to access nginx from localhost ex: http://127.0.0.1:8080
I get ERR_CONNECTION_REFUSED

kubectl apply -f nginx.yml
deployment.apps/nginx-deployment-name created

kubectl apply -f nginx-service.yml
service/nginx-service-name created

Deployment yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment-name
  labels:
    name: nginx-deployment-name-label
spec:
  replicas: 3
  selector:
    matchLabels:
      name: nginx-template-name
  template:
    metadata:
      labels:
        name: nginx-template-name
    spec:
      containers:
      - name: nginx-container-name
        image: nginx
        ports:
        - containerPort: 8080

Service yml

apiVersion: v1
kind: Service
metadata:
  name: nginx-service-name
spec:
  selector:
    name: nginx-deployment-name-label
  type: NodePort
  ports:
  - name: http
    port: 8080
    targetPort: 8080
    nodePort: 30003
    protocol: TCP

CodePudding user response:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    name: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      name: nginx
  template:
    metadata:
      labels:
        name: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80

---
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    name: nginx
spec:
  type: NodePort
  ports:
    - port: 80
      nodePort: 30080
      name: http
  selector:
    name: nginx

Then if you are on minikube for example:

➜  minikube ip
192.168.49.2

curl http://192.168.49.2:30080/
  • Related