-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deploy to kubernetes and use kubernetes service discovery
- Loading branch information
felix
committed
Dec 29, 2021
1 parent
3c4520c
commit 773dc0c
Showing
12 changed files
with
507 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
# 1. create namespace | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: dlw-dev | ||
labels: | ||
environment: development | ||
resourceVersion : "2" | ||
|
||
--- | ||
# 2. create ResourceQuota for the namespace | ||
apiVersion: v1 | ||
kind: ResourceQuota | ||
metadata: | ||
name: dlw-dev-quota | ||
namespace: dlw-dev | ||
spec: | ||
hard: | ||
requests.cpu: "1" | ||
requests.memory: 1Gi | ||
limits.cpu: "2" | ||
limits.memory: 4Gi | ||
|
||
--- | ||
# 3.1 create roles for access pods | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: dlw-service-role | ||
namespace: dlw-dev | ||
rules: | ||
- apiGroups: [""] | ||
resources: ["pods"] | ||
verbs: ["get", "list", "patch"] # You can also use ["*"] | ||
|
||
--- | ||
# 3.2 bind role to the default service account in the namespace | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
# This role binding allows "jane" to read pods in the "default" namespace. | ||
# You need to already have a Role named "pod-reader" in that namespace. | ||
kind: RoleBinding | ||
metadata: | ||
name: dlw-service-role-binding | ||
namespace: dlw-dev | ||
subjects: | ||
# You can specify more than one "subject" | ||
- kind: User | ||
name: system:serviceaccount:dlw-dev:default # "name" is case sensitive | ||
apiGroup: rbac.authorization.k8s.io | ||
roleRef: | ||
# "roleRef" specifies the binding to a Role / ClusterRole | ||
kind: Role #this must be Role or ClusterRole | ||
name: dlw-service-role # this must match the name of the Role or ClusterRole you wish to bind to | ||
apiGroup: rbac.authorization.k8s.io | ||
|
||
--- | ||
# 4.1 create deployment with pod spec for date-api service | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: dlw-deployment-dev-date | ||
namespace: dlw-dev | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: date-api | ||
template: | ||
metadata: | ||
labels: | ||
app: date-api | ||
spec: | ||
containers: | ||
- name: date-api | ||
image: date-api:1.0.0 | ||
ports: | ||
- containerPort: 8383 | ||
env: | ||
- name: AWS_ACCESS_KEY_ID | ||
value: "xx" | ||
- name: AWS_SECRET_ACCESS_KEY | ||
value: "yy" | ||
- name: AWS_REGION | ||
value: "ap-southeast-1" | ||
resources: | ||
requests: | ||
memory: 256Mi | ||
cpu: "128m" | ||
limits: | ||
memory: 512Mi | ||
cpu: "256m" | ||
|
||
--- | ||
# 4.2 create deployment with pod spec for memo-api service | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: dlw-deployment-dev-memo | ||
namespace: dlw-dev | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: memo-api | ||
template: | ||
metadata: | ||
labels: | ||
app: memo-api | ||
spec: | ||
containers: | ||
- name: memo-api | ||
image: memo-api:1.0.0 | ||
ports: | ||
- containerPort: 8282 | ||
env: | ||
- name: AWS_ACCESS_KEY_ID | ||
value: "xx" | ||
- name: AWS_SECRET_ACCESS_KEY | ||
value: "yy" | ||
- name: AWS_REGION | ||
value: "ap-southeast-1" | ||
resources: | ||
requests: | ||
memory: 256Mi | ||
cpu: "128m" | ||
limits: | ||
memory: 512Mi | ||
cpu: "256m" | ||
|
||
--- | ||
# 4.3 create deployment with pod spec for user-api service | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: dlw-deployment-dev-user | ||
namespace: dlw-dev | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: user-api | ||
template: | ||
metadata: | ||
labels: | ||
app: user-api | ||
spec: | ||
containers: | ||
- name: user-api | ||
image: user-api:1.0.0 | ||
ports: | ||
- containerPort: 8181 | ||
env: | ||
- name: AWS_ACCESS_KEY_ID | ||
value: "xx" | ||
- name: AWS_SECRET_ACCESS_KEY | ||
value: "yy" | ||
- name: AWS_REGION | ||
value: "ap-southeast-1" | ||
resources: | ||
requests: | ||
memory: 256Mi | ||
cpu: "128m" | ||
limits: | ||
memory: 512Mi | ||
cpu: "256m" | ||
|
||
--- | ||
# 5. create service for with NodePort exposed | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: dlw-service | ||
namespace: dlw-dev | ||
spec: | ||
type: NodePort #default is ClusterIP which is only accessible inside kubernetes | ||
selector: | ||
app: date-api | ||
ports: | ||
- name: http | ||
protocol: TCP | ||
port: 8080 | ||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.