Skip to content

Commit

Permalink
add nginx ingress-controller and ingress for microservice
Browse files Browse the repository at this point in the history
  • Loading branch information
felix committed Dec 30, 2021
1 parent 773dc0c commit 0aca9ee
Show file tree
Hide file tree
Showing 3 changed files with 809 additions and 16 deletions.
101 changes: 85 additions & 16 deletions deployment/kubernetes/deployment_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
name: dlw-dev
labels:
environment: development
resourceVersion : "2"
resourceVersion : "4"

---
# 2. create ResourceQuota for the namespace
Expand All @@ -17,9 +17,9 @@ metadata:
spec:
hard:
requests.cpu: "1"
requests.memory: 1Gi
requests.memory: 2Gi
limits.cpu: "2"
limits.memory: 4Gi
limits.memory: 3Gi

---
# 3.1 create roles for access pods
Expand Down Expand Up @@ -61,7 +61,7 @@ metadata:
name: dlw-deployment-dev-date
namespace: dlw-dev
spec:
replicas: 2
replicas: 1
selector:
matchLabels:
app: date-api
Expand All @@ -77,9 +77,9 @@ spec:
- containerPort: 8383
env:
- name: AWS_ACCESS_KEY_ID
value: "xx"
value: "abc"
- name: AWS_SECRET_ACCESS_KEY
value: "yy"
value: "xyz"
- name: AWS_REGION
value: "ap-southeast-1"
resources:
Expand All @@ -98,7 +98,7 @@ metadata:
name: dlw-deployment-dev-memo
namespace: dlw-dev
spec:
replicas: 2
replicas: 1
selector:
matchLabels:
app: memo-api
Expand All @@ -114,9 +114,9 @@ spec:
- containerPort: 8282
env:
- name: AWS_ACCESS_KEY_ID
value: "xx"
value: "abc"
- name: AWS_SECRET_ACCESS_KEY
value: "yy"
value: "xyz"
- name: AWS_REGION
value: "ap-southeast-1"
resources:
Expand All @@ -135,7 +135,7 @@ metadata:
name: dlw-deployment-dev-user
namespace: dlw-dev
spec:
replicas: 2
replicas: 1
selector:
matchLabels:
app: user-api
Expand All @@ -151,9 +151,9 @@ spec:
- containerPort: 8181
env:
- name: AWS_ACCESS_KEY_ID
value: "xx"
value: "abc"
- name: AWS_SECRET_ACCESS_KEY
value: "yy"
value: "xyz"
- name: AWS_REGION
value: "ap-southeast-1"
resources:
Expand All @@ -165,11 +165,11 @@ spec:
cpu: "256m"

---
# 5. create service for with NodePort exposed
# 5.1 create service for with NodePort exposed
apiVersion: v1
kind: Service
metadata:
name: dlw-service
name: dlw-service-date
namespace: dlw-dev
spec:
type: NodePort #default is ClusterIP which is only accessible inside kubernetes
Expand All @@ -178,7 +178,76 @@ spec:
ports:
- name: http
protocol: TCP
port: 8080
port: 8383
targetPort: 8383 # can use port name reference or port number, container name is more flexible as we can change port number
nodePort: 30080 #default range from: 30000 - 32767

---
# 5.2 create service for with NodePort exposed
apiVersion: v1
kind: Service
metadata:
name: dlw-service-memo
namespace: dlw-dev
spec:
type: ClusterIP #default is ClusterIP which is only accessible inside kubernetes
selector:
app: memo-api
ports:
- name: http
protocol: TCP
port: 8282
targetPort: 8282 # can use port name reference or port number, container name is more flexible as we can change port number

---
# 5.2 create service for with NodePort exposed
apiVersion: v1
kind: Service
metadata:
name: dlw-service-user
namespace: dlw-dev
spec:
type: ClusterIP #default is ClusterIP which is only accessible inside kubernetes
selector:
app: user-api
ports:
- name: http
protocol: TCP
port: 8181
targetPort: 8181 # can use port name reference or port number, container name is more flexible as we can change port number

---
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-resource-dlw
namespace: dlw-dev
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /date/(.*)
pathType: Prefix
backend:
service:
name: dlw-service-date
port:
number: 8383
- path: /memo/(.*)
pathType: Prefix
backend:
service:
name: dlw-service-memo
port:
number: 8282
- path: /user/(.*)
pathType: Prefix
backend:
service:
name: dlw-service-user
port:
number: 8181

Loading

0 comments on commit 0aca9ee

Please sign in to comment.