Problem: I ran each services in different container. It’s easy to call service in IP. But this way is foolish. So need to improve to set domain name for services in Kubernetes 😭
What are Microservices?
Microservices are an architectural and organizational approach to software development where software is composed of small independent services that communicate over well-defined APIs. These services are owned by small, self-contained teams.
Microservices architectures make applications easier to scale and faster to develop, enabling innovation and accelerating time-to-market for new features.
Solution: it’s easy to scale up/down services. Refence below to set domain name for services in Kubernetes.
A. each Services:
- Product service
apiVersion: v1
kind: Service
metadata:
name: product-service
spec:
ports:
- port: 8070
targetPort: 8070
protocol: TCP
selector:
app: product
- Jwt service
apiVersion: v1
kind: Service
metadata:
name: jwt-service
spec:
ports:
- port: 8080
targetPort: 8080
protocol: TCP
selector:
app: jwt
- Frontendpage service
apiVersion: v1
kind: Service
metadata:
name: frontendpage-service
spec:
ports:
- port: 8090
targetPort: 8090
protocol: TCP
selector:
app: frontendpage-pod
- mysql service
apiVersion: v1
kind: Service
metadata:
name: mysql-service
spec:
ports:
- port: 3306
targetPort: 3306
protocol: TCP
selector:
app: mysql
Ingress controller:
A API object that manages external access to the services in a cluster, typically HTTP. Ingress can provide load balancing, SSL termination and name-based virtual hosting.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: frontendpage-ingress
namespace: default
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: demopage
http:
paths:
- path: /
backend:
serviceName: frontendpage-service
servicePort: 8090
- path: /jwt
backend:
serviceName: jwt-service
servicePort: 8080
- path: /ajaxProduct
backend:
serviceName: product-service
servicePort: 8070
- path: /h
backend:
serviceName: helloworld-service
servicePort: 3000
nginx. ingress. kubernetes. io/rewrite-target:/ = It means prefix match “/” If you skip this annotation. The Ingress only match “/”
namespace = All of service follow this ingress controller rule. 😁