Expose multiple apps in gcloud kubernetes cluster - kubernetes

I have 2 apps running on gcloud kubernetes cluster and exposed via services. I followed steps from https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer, for serving multiple applications on load balancer.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: fanout-ingress
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: nginx
servicePort: 80
- path: /app1
backend:
serviceName: app1server
servicePort: 8080
- path: /app2
backend:
serviceName: app2server
servicePort: 8080
services looks like this :
apiVersion: v1
kind: Service
metadata:
name: app1server
spec:
ports:
- name: app1-port
port: 8080
type: NodePort
----
apiVersion: v1
kind: Service
metadata:
name: app1server
spec:
ports:
- name: app2-port
port: 8080
type: NodePort
But I am getting default backend - 404 error when I try to access http://ip/app1/test or http://ip/app2/test
Can anyone please tell me how I can achieve this?

Related

Kuberenetes - Custom domain ingress

I have a cluster IP service and a Ingress. What should my custom domain name point to if I need to route traffic using Ingress? Backend is plain http.
Do I have to create a AWS Loadbalancer with target groups pointing to k8s nodes? And use domain alias pointing to aws loadbalancer? I was reading this K8s article and they're pointing to a subdomain.
Ingress.yaml:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
creationTimestamp: "2022-08-05T00:50:41Z"
generation: 1
labels:
app: testing
name: httpd
namespace: default
spec:
rules:
- host: www.example.com
http:
paths:
- backend:
service:
name: httpd
port:
number: 8080
path: /
pathType: ImplementationSpecific
tls:
- hosts:
- www.example.com
secretName: tls-secret
status:
loadBalancer: {}
service.yaml:
kind: Service
metadata:
creationTimestamp: "2022-08-05T00:50:41Z"
labels:
app: testing
name: httpd
namespace: default
spec:
clusterIP: 100.65.xxx.xx
clusterIPs:
- 100.65.xxx.xx
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
name: httpd
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
Yes you have to create the Load Balancer however that will auto managed by the K8s service.
You can use the Nginx or other ingress controller as per requirement.
You can checkout this Nice official doc from AWS : https://aws.amazon.com/blogs/opensource/network-load-balancer-nginx-ingress-controller-eks/
Once you deploy the Nginx ingress controller it will manage the ingress resource and the Nginx controller will get the public LB.
Example :
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
tls:
- hosts:
- anthonycornell.com
secretName: tls-secret
rules:
- host: anthonycornell.com
http:
paths:
- path: /apple
backend:
serviceName: apple-service
servicePort: 5678
- path: /banana
backend:
serviceName: banana-service
servicePort: 5678

Kubernetes Multi Path Routing Issue

I’m using AWS EKS with aws load balancer controller. I have created five services and deployments and make a single ingress file. The deployment has done successfully but when i access ALB-URL with below mentioned paths in ingress file. It gives me 404 error. But the when i used EXTERNALIP:PORT/PATH it’s working fine. How can I fix the issue ?
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
namespace: ee-be
name: ee-ingress
annotations:
# Ingress Core Settings
kubernetes.io/ingress.class: "alb"
alb.ingress.kubernetes.io/scheme: internet-facing
# Health Check Settings
alb.ingress.kubernetes.io/healthcheck-protocol: HTTP
alb.ingress.kubernetes.io/healthcheck-port: '8012'
alb.ingress.kubernetes.io/healthcheck-path: /
alb.ingress.kubernetes.io/healthcheck-interval-seconds: '15'
alb.ingress.kubernetes.io/healthcheck-timeout-seconds: '5'
alb.ingress.kubernetes.io/success-codes: '200'
alb.ingress.kubernetes.io/healthy-threshold-count: '2'
alb.ingress.kubernetes.io/unhealthy-threshold-count: '2'
spec:
rules:
- http:
paths:
- path: /rwds/*
backend:
serviceName: ee-rwds
servicePort: 8012
- path: /point/*
backend:
serviceName: ee-pe
servicePort: 8013
- path: /user-mgt/*
backend:
serviceName: ee-um
servicePort: 8014
Perhaps you have a ClusterIP service instead an ExternalName service.
ExternalName service example:
apiVersion: v1
kind: Service
metadata:
name: my_service_name
namespace: my_ingress_namespace
spec:
externalName: my_service_name.my_service_namespace_name.svc.cluster.local
ports:
- port: 80
protocol: TCP
targetPort: 80
sessionAffinity: None
type: ExternalName
status:
loadBalancer: {}

default backend - 404 returned from nginx-controller when dns is used

a bit of background is that I have setup an Azure Kubernetes Service cluster and deployed a basic .Net Core api as a deployment object. I then deployed a nodeport service to expose the api and then deployed a nginx-controller and an ingress object to configure it. I use the IP of the ingress-controller to route the request and that works eg.http://1.2.3.4/hello-world-one/api/values.
But when I replace the Ip with the generated dns, somehow the path is ignored and I get the default backend - 404 returned from the nginx controller. The expected behaviour is that the dns will resolve then the path "api/values" will be sent to my service.
Can anyone help me with this?
Thanks in advance.
My deployment, service and ingress configs are below.
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: test-deployment
labels:
app: test
spec:
replicas: 1
selector:
matchLabels:
app: test
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
template:
metadata:
labels:
app: test
spec:
containers:
- name: test-service
image: <my-repo>.azurecr.io/testservice
imagePullPolicy: Always
ports:
- name: tcp
containerPort: 80
imagePullSecrets:
- name: regsecret
---
apiVersion: v1
kind: Service
metadata:
name: frontend
spec:
type: NodePort
selector:
app: test
ports:
- name: http
port: 32768
targetPort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: hello-world-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.global-static-ip-name: dev-pip-usw-qa-aks
kubernetes.io/ingress.class: addon-http-application-routing
spec:
rules:
- host: hello-world-ingress.be543d4af69d4c7ca489.westus.aksapp.io
- http:
paths:
- path: /
backend:
serviceName: frontend
servicePort: http
- path: /hello-world-one
backend:
serviceName: frontend
servicePort: http
- path: /hello-world-two
backend:
serviceName: frontend
servicePort: http
pretty sure rules should look like this:
rules:
- host: hello-world-ingress.be543d4af69d4c7ca489.westus.aksapp.io
http:
paths:
- path: /
backend:
serviceName: frontend
servicePort: http
- path: /hello-world-one
backend:
serviceName: frontend
servicePort: http
- path: /hello-world-two
backend:
serviceName: frontend
servicePort: http
reading: https://kubernetes.io/docs/concepts/services-networking/ingress/#types-of-ingress

define an url for an application inside kubernetes

hy folks
Currently i trying to setup an url in my kubernetes
I wrote a service to be able to connect to the dns to resolv all external URL.
I defined as well an Ingress
kind: Ingress
metadata:
name: dnsingressresource
spec:
# tls:
# - hosts:
# - < domain>
# secretName: <tls_secret_name>
rules:
- host: cloud.devlan.xx.xxx
http:
paths:
- path: /mobdev1/auth
backend:
serviceName: service-cas-nodeport
servicePort: 2488
if i want to go to the url of my application i've to write this
https://cloud.devlan.xx.xxx:2488/mobdev1/auth/login
I trying to get this
https://cloud.devlan.xx.xxx/mobdev1/auth/login
do you know how i can get it ?
You should specify port 80 for your Service and targetPort should be the port in your container
Defining a Service
deployment.yaml
kind: Deployment
...
spec:
containers:
- name: my-app
image: "my-image:my-tag"
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 2488
protocol: TCP
service.yaml
apiVersion: v1
kind: Service
...
spec:
type: NodePort
ports:
- port: 80
targetPort: 2488
protocol: TCP
name: http
ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
...
spec:
backend:
serviceName: my-service
servicePort: 80

Kubernetes routing to specific pod in function of a param in url

The need I have just looks like this stuff :
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: http
spec:
serviceName: "nginx-set"
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: gcr.io/google_containers/nginx-slim:0.8
ports:
- containerPort: 80
name: http
----
apiVersion: v1
kind: Service
metadata:
name: nginx-set
labels:
app: nginx
spec:
ports:
- port: 80
name: http
clusterIP: None
selector:
app: nginx
Here is the interesting part :
apiVersion: voyager.appscode.com/v1beta1
kind: Ingress
metadata:
name: test-ingress
namespace: default
spec:
rules:
- host: appscode.example.com
http:
paths:
- path: '/testPath'
backend:
hostNames:
- web-0
serviceName: nginx-set #! There is no extra service. This
servicePort: '80' # is the Statefulset's Headless Service
I'm able to target a specific pod because of setting the hostName in function of the url.
Now I'd like to know if it's possible in kubernetes to create a rule like that
apiVersion: voyager.appscode.com/v1beta1
kind: Ingress
metadata:
name: test-ingress
namespace: default
spec:
rules:
- host: appscode.example.com
http:
paths:
- path: '/connect/(\d+)'
backend:
hostNames:
- web-(result of regex match with \d+)
serviceName: nginx-set #! There is no extra service. This
servicePort: '80' # is the Statefulset's Headless Service
or if I have to wrote a rule for each pod ?
Sorry that isn't possible, the best solution is to create multiple paths, each one referencing one pod:
apiVersion: voyager.appscode.com/v1beta1
kind: Ingress
metadata:
name: test-ingress
namespace: default
spec:
rules:
- host: appscode.example.com
http:
paths:
- path: '/connect/0'
backend:
hostNames:
- web-0
serviceName: nginx-set
servicePort: '80'
- path: '/connect/1'
backend:
hostNames:
- web-1
serviceName: nginx-set
servicePort: '80'