Setup Kubernetes with LB & ingress

11/24/2019

I'm trying to configure a single node kubernetes clustor with a load balancer and ingress but I cant reach it from my external IP. Also if I try to curl/wget the internal IP of the LB it doesen't work. I can propperly curl/wget the service itself. Can anyone help me?

configuration

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-ingress
spec:
  rules:
    - host: MY_DOMAIN
      http:
        paths:
        - path: /
          backend:
            serviceName: apple-service
            servicePort: 5678
---

kind: Service
apiVersion: v1
metadata:
  name: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  type: LoadBalancer
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
  ports:
    - name: http
      port: 80
      targetPort: 80
    - name: https
      port: 443
      targetPort: 443

  externalIPs:
    - XX.XX.XX.XX


---

kind: Pod
apiVersion: v1
metadata:
  name: apple-app
  labels:
    app: apple
spec:
  containers:
    - name: apple-app
      image: hashicorp/http-echo
      args:
        - "-text=apple"

---

kind: Service
apiVersion: v1
metadata:
  name: apple-service
spec:
  selector:
    app: apple
  ports:
    - port: 5678 # Default port for image

kubectl get all

NAME            READY   STATUS    RESTARTS   AGE
pod/apple-app   1/1     Running   0          12m

NAME                    TYPE           CLUSTER-IP      EXTERNAL-IP       PORT(S)                      AGE
service/apple-service   ClusterIP      10.108.8.152    <none>            5678/TCP                     12m
service/ingress-nginx   LoadBalancer   10.111.230.95   XX.XX.XX.XX  80:30338/TCP,443:31035/TCP   10m
service/kubernetes      ClusterIP      10.96.0.1       <none>            443/TCP                      6d

kubectl get ingress

NAME           HOSTS   ADDRESS   PORTS   AGE
test-ingress   *                 80      6d

curl 10.107.97.101:5678

apple

curl XX.XX.XX.XX:80 (external ip)|localhost:80|MY_DOMAIN:80

curl: (7) Failed to connect to XX.XX.XX.XX port 80: Connection refused

installation

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

mkdir $HOME/.kube -p
sudo cp /etc/kubernetes/admin.conf $HOME/.kube/
sudo chown $(id -u):$(id -g) $HOME/.kube/admin.conf
export KUBECONFIG=$HOME/.kube/admin.conf
echo "export KUBECONFIG=$HOME/.kube/admin.conf" | tee -a ~/.bashrc


# flanel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/k8s-manifests/kube-flannel-rbac.yml

# untained master to use as container host
kubectl taint nodes --all node-role.kubernetes.io/master-


# Install helm - for lets encrypt
sudo snap install helm --classic
PATH=$PATH:/snap/bin

# enable helm
helm init
helm install --name cert-manager -f cert-manager-values.yaml --namespace=default stable/cert-manager --set rbac.create=false
helm repo add jetstack https://charts.jetstack.io

# create letsencrypt 
kubectl create namespace cert-manager
kubectl label namespace cert-manager certmanager.k8s.io/disable-validation=true
kubectl apply -f https://raw.githubusercontent.com/jetstack/cert-manager/release-0.8/deploy/manifests/00-crds.yaml
-- F-Froehlich
kubernetes
kubernetes-ingress

1 Answer

11/24/2019

Hi @Fabi your service name in test-ingress spec should be

serviceName: apple-service

and also remove

externalTrafficPolicy: Local

from your ingress-nginx service spec.

Edit your ingress spec to this:

apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: name: test-ingress spec: rules: - host: * http: paths: - path: /* backend: serviceName: apple-service servicePort: 5678

-- Arunagiriswaran Ezhilan
Source: StackOverflow