I
I
Ivan Vekov2020-10-29 18:46:09
Docker
Ivan Vekov, 2020-10-29 18:46:09

How to expose the Minikube service to an external network?

Good afternoon.

0) There is an image:

spoiler
FROM nginx:latest
MAINTAINER Vekov Ivan <[email protected]>
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
RUN find /etc/nginx/ -type f -exec sed -i 's/80/8000/g' {} +
RUN mkdir "/usr/share/nginx/html/health/"
RUN echo "{'status':'OK'}" > /usr/share/nginx/html/health/index.html
RUN mkdir "/usr/share/nginx/html/version/"
RUN echo "{'version':'0.1'}" > /usr/share/nginx/html/version/index.html
EXPOSE 8000
CMD ["nginx"]

1) There is a VPS
2) A minicube with a driver is installed = docker
3) There is a deployment
spoiler
apiVersion: apps/v1
kind: Deployment
metadata:
    name: myapp-deployment
spec:
    replicas: 2
    selector:
       matchLabels:
          app: myapp
    template:
       metadata:
          labels:
             app: myapp
       spec:
          containers:
          - name: myapp
            image: ivekov/ivekov:latest
            ports:
              - name: web
                containerPort: 8000
            livenessProbe:
              httpGet:
                port: 8000
                path: /health/
              initialDelaySeconds: 10
              periodSeconds: 5
              timeoutSeconds: 2
            readinessProbe:
              httpGet:
                port: 8000
                path: /health/
              initialDelaySeconds: 10
              periodSeconds: 5

4) There is a service:
spoiler
apiVersion: v1
kind: Service
metadata:
  name: myapp-service
spec:
  selector:
    app: myapp
  ports:
    - protocol: TCP
      port: 80
      targetPort: web
  type: NodePort

5) There is ingress:
spoiler
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: myapp-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
    - host: arch.homework
      http:
        paths:
          - path: /test/ivekov($|/)(.*)
            pathType: Prefix
            backend:
              service: 
                name: myapp-service
                port:
                  number: 80

6) If you do curl from the machine to arch.homework/(*)/health/ - OK answers.
7) If you request this path through the browser - Page not found.
8) Ingress addon is enabled
9) Service does not have External_IP

Question - what went wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Vekov, 2020-11-24
@vekov

So, the answer to this question was as follows:
It was necessary to install nginx on the server, and make proxy_pass for ingress.
Like this:

server {
    listen 80;
    server_name blog.zeroxzed.ru;
    access_log /var/log/nginx/blog.zeroxzed.ru-access.log;
    error_log /var/log/nginx/blog.zeroxzed.ru-error.log;

location / {
    proxy_pass http://192.168.13.31;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    }
}

We place this in etc/nginx/sites-available/default
IP address " 192.168.13.31 " of course we change to ingress ip.
You can get it through:
kubectl get ingress
It seems to be :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question