Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubernetes deployment #58

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ RUN apk update && apk add curl
RUN npm install -g @nestjs/cli
WORKDIR /usr/src/app
COPY . .
RUN sed -i 's/RUNNING_ON_DOCKER=false/RUNNING_ON_DOCKER=true/g' .env
RUN npm install
RUN npm run build
CMD ["node","dist/main.js"]
Expand Down
17 changes: 17 additions & 0 deletions k8s/cassandra/cassandra-client-service-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
kind: Service
apiVersion: v1
metadata:
namespace: hi-cassandra
name: cassandra-client
labels:
app: cassandra
type: LoadBalancer
spec:
type: LoadBalancer
ports:
- name: cql
protocol: TCP
port: 9042
targetPort: 9042
selector:
app: cassandra
14 changes: 14 additions & 0 deletions k8s/cassandra/cassandra-headless-service-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
namespace: hi-cassandra
labels:
app: cassandra
name: cassandra-headless
spec:
publishNotReadyAddresses: true
clusterIP: None
ports:
- port: 9042
selector:
app: cassandra
4 changes: 4 additions & 0 deletions k8s/cassandra/cassandra-namespace-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: hi-cassandra
101 changes: 101 additions & 0 deletions k8s/cassandra/cassandra-statefulset-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: cassandra-nodes
namespace: hi-cassandra
labels:
app: cassandra
spec:
serviceName: cassandra
podManagementPolicy: Parallel
replicas: 2
selector:
matchLabels:
app: cassandra
template:
metadata:
labels:
app: cassandra
spec:
volumes:
- name: cassandra-data
persistentVolumeClaim:
claimName: cassandra-data
terminationGracePeriodSeconds: 1800
containers:
- name: cassandra
image: cassandra
imagePullPolicy: Always
ports:
- containerPort: 7000
name: intra-node
- containerPort: 7001
name: tls-intra-node
- containerPort: 7199
name: jmx
- containerPort: 9042
name: cql
resources:
limits:
cpu: "500m"
memory: 1Gi
requests:
cpu: "500m"
memory: 1Gi
securityContext:
capabilities:
add:
- IPC_LOCK
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- nodetool drain
env:
- name: MAX_HEAP_SIZE
value: 512M
- name: HEAP_NEWSIZE
value: 100M
# - name: CASSANDRA_SEEDS
# value: "hi-cassandra.svc.cluster.local"
- name: CASSANDRA_CLUSTER_NAME
value: "hi-cassandra-cluster"
- name: CASSANDRA_DC
value: "DC1"
- name: CASSANDRA_RACK
value: "Rack1"
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
readinessProbe:
exec:
command:
- /bin/bash
- -c
- nodetool status
initialDelaySeconds: 30
timeoutSeconds: 30
livenessProbe:
exec:
command:
- /bin/bash
- -c
- nodetool status
initialDelaySeconds: 30
timeoutSeconds: 30
volumeMounts:
- name: cassandra-data
mountPath: /var/lib/cassandra
volumeClaimTemplates:
- metadata:
name: cassandra-data
namespace: hi-cassandra
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: standard
resources:
requests:
storage: 1Gi
33 changes: 33 additions & 0 deletions k8s/ingress/ingress-controller-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: extensions/vibetal
kind: Deployment
metadata:
name: hi-ingress-controller
spec:
replicas: 1
selector:
matchLabels:
name: nginix-ingress
template:
metadata:
labels:
name: nginix-ingress
spec:
containers:
- name: nginix-ingress-controller
image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller
args:
- /nginix-ingress-controller
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: PODE_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
ports:
- containerPort: 80
name: http
- containerPort: 443
name: https
19 changes: 19 additions & 0 deletions k8s/ingress/ingress-resources-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hi-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx-class
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hi-web-service
port:
number: 80

20 changes: 20 additions & 0 deletions k8s/ingress/ingress-service-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Service
metadata:
name: hi-nginx-service
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
name: http
- port: 443
targetPort: 443
protocol: TCP
name: https
selector:
name: nginix-ingress



4 changes: 4 additions & 0 deletions k8s/ingress/ingress-serviceaccount-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: hi-service-account
22 changes: 22 additions & 0 deletions k8s/rabbitmq/rabbitmq-client-service-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
kind: Service
apiVersion: v1
metadata:
namespace: hi-rabbitmq
name: rabbitmq-client
labels:
app: rabbitmq
type: LoadBalancer
spec:
type: LoadBalancer
ports:
- name: http
protocol: TCP
port: 15672
- name: prometheus
protocol: TCP
port: 15692
- name: amqp
protocol: TCP
port: 5672
selector:
app: rabbitmq
22 changes: 22 additions & 0 deletions k8s/rabbitmq/rabbitmq-configmap-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: rabbitmq-config
namespace: hi-rabbitmq
data:
enabled_plugins: |
[rabbitmq_peer_discovery_k8s, rabbitmq_management, rabbitmq_prometheus].
rabbitmq.conf: |
## Clustering
cluster_formation.peer_discovery_backend = rabbit_peer_discovery_k8s
cluster_formation.k8s.host = kubernetes.default.svc.cluster.local
cluster_formation.k8s.port = 6443
cluster_formation.k8s.address_type = hostname
cluster_formation.node_cleanup.interval = 10
cluster_formation.node_cleanup.only_log_warning = true
cluster_partition_handling = autoheal
cluster_formation.k8s.service_name = rabbitmq-headless
# queue master locator
queue_master_locator=min-masters
# enable guest user
loopback_users.guest = false
21 changes: 21 additions & 0 deletions k8s/rabbitmq/rabbitmq-headless-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v1
kind: Service
metadata:
name: rabbitmq-headless
namespace: hi-rabbitmq
spec:
clusterIP: None
ports:
- name: epmd
port: 4369
protocol: TCP
targetPort: 4369
- name: cluster-rpc
port: 25672
protocol: TCP
targetPort: 25672
selector:
app: rabbitmq
type: ClusterIP
sessionAffinity: None
publishNotReadyAddresses: true
4 changes: 4 additions & 0 deletions k8s/rabbitmq/rabbitmq-namespace-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: hi-rabbitmq
32 changes: 32 additions & 0 deletions k8s/rabbitmq/rabbitmq-rbac-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: rabbitmq
namespace: hi-rabbitmq
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: rabbitmq
namespace: hi-rabbitmq
rules:
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get"]
- apiGroups: [""]
resources: ["events"]
verbs: ["create"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: rabbitmq
namespace: hi-rabbitmq
subjects:
- kind: ServiceAccount
name: rabbitmq
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: rabbitmq
14 changes: 14 additions & 0 deletions k8s/rabbitmq/rabbitmq-secrets-definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Secret
metadata:
name: erlang-cookie
data:
cookie: PUT_YOUR_COOKIE_HERE
---
apiVersion: v1
kind: Secret
metadata:
name: rabbitmq-admin
data:
user: PUT_THE_USERNAME_HERE
pass: PUT_THE_PASSWORD_HERE
16 changes: 16 additions & 0 deletions k8s/rabbitmq/rabbitmq-secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Secret
metadata:
name: erlang-cookie
namespace: hi-rabbitmq
data:
.erlang.cookie: UE5JUkRNSFVBV0tDT1hPU1dEU1A=
---
apiVersion: v1
kind: Secret
metadata:
name: rabbitmq-admin
namespace: hi-rabbitmq
data:
user: bWFuaWsyNzA4
pass: RG1hbmlrYUAyNzI3
Loading
Loading