minikube // attempt for pods to communicate without a service

basics

let’s start two pods so we can do the test

#minikube delete --all
minikube start --driver=docker
minikube addons enable metrics-server

kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0
kubectl create deployment devuan --image=pbraun9/devuan

kubectl get pods -o wide    # notice IPs
kubectl get svc         # just k8s
kubectl get endpoints       # idem

kubectl exec -ti devuan-57c996788d-fk9nd -- bash

the pods can talk to each other without a service (no DNS)

ping -c1 10.244.0.3
ping -c1 web
curl 10.244.0.3:8080

==> IP responds but DNS doesn’t, micro-service is available anyhow

next step

now let’s try to make ingress talk to the pods directly

minikube addons enable ingress
kubectl get pods -n ingress-nginx
cat > ingress-next-step.yml <<EOF

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-next-step
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - host: hello-world.info
      http:
    paths:
      - path: /
        pathType: Prefix
        backend:
          service:
        name: web
        port:
          number: 8080

EOF
kubectl apply -f ingress-next-step.yml

now let’s try

from within

kubectl get pods -o wide
kubectl get pods -o wide -n ingress-nginx
kubectl exec -ti ingress-nginx-controller-7799c6795f-qjm8t -n ingress-nginx -- bash

check

ping -c1 10.244.0.3
ping -c1 web
curl 10.244.0.3:8080

from outside

curl --resolve hello-world.info:80:192.168.49.2 -i http://hello-world.info # NOK

==> doesn’t work because it goes through the service

kubectl get ingress ingress-next-step -o yaml

for ingress to work normally we absolutely need a service

kubectl expose deploy web --type=ClusterIP --port=8080
kubectl get endpoints

==> the endpoint got created and shows the true IP behind the service

resources

https://stackoverflow.com/questions/58298889/can-a-pod-directly-call-another-pod

https://stackoverflow.com/questions/43941772/get-yaml-for-deployed-kubernetes-services

https://kubernetes.io/docs/concepts/services-networking/ingress/#resource-backend


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun