Skip to content

Commit a8b59c0

Browse files
author
Innokentii Kozlov
committed
init kuberentes
1 parent ded6c13 commit a8b59c0

File tree

13 files changed

+221
-21
lines changed

13 files changed

+221
-21
lines changed

.github/workflows/cloud-deploy.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222
uses: ./.github/workflows/lint-iac.yaml
2323
secrets: inherit
2424

25-
aws-infra-deploy:
26-
name: AWS Infrastructure Deploy
27-
needs: lint-iac
28-
uses: ./.github/workflows/aws-infra-deploy.yaml
29-
secrets: inherit
25+
# aws-infra-deploy:
26+
# name: AWS Infrastructure Deploy
27+
# needs: lint-iac
28+
# uses: ./.github/workflows/aws-infra-deploy.yaml
29+
# secrets: inherit

Makefile

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ generate-tls-certificates:
3232
@sudo chmod 600 ${SSL_DIR}/server.key
3333

3434

35-
.PHONY: database-start-local
36-
database-start-local:
35+
.PHONY: database-start
36+
database-start:
3737
docker compose -f $(shell pwd)/infrastructure/docker/docker-compose.database.yaml up -d
38+
39+
40+
.PHONY: run-migrations
41+
run-migrations:
3842
docker run \
3943
-ti \
4044
--rm \
@@ -44,14 +48,19 @@ database-start-local:
4448
--volume $(shell pwd)/infrastructure/docker/ssl/server.crt:/migrations/ssl/server.crt \
4549
--volume $(shell pwd)/infrastructure/docker/ssl/server.key.bak:/migrations/ssl/server.key \
4650
ghcr.io/kesha123/nodejs-rest-api/migrations:${MIGRATIONS_IMAGE_TAG}
51+
52+
53+
.PHONY: insert-data
54+
insert-data:
4755
docker exec postgres sh -c "psql -U postgres -d postgres -f /opt/sql/insert.sql"
4856

4957

50-
.PHONY: api-start-local
51-
api-start-local:
58+
.PHONY: api-start
59+
api-start:
5260
docker compose -f $(shell pwd)/infrastructure/docker/docker-compose.yaml up -d
5361

54-
.PHONY: stack-stop-local
55-
stack-stop-local:
62+
63+
.PHONY: stack-stop
64+
stack-stop:
5665
docker compose -f $(shell pwd)/infrastructure/docker/docker-compose.database.yaml down
5766
docker compose -f $(shell pwd)/infrastructure/docker/docker-compose.yaml down

infrastructure/cloud/index.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const prodSg = createProdSg(projectConfig.project_name, 'prod-sg', {
7777
},
7878
});
7979

80-
const kubernetesNode = new aws.ec2.Instance(
80+
const node = new aws.ec2.Instance(
8181
`${projectConfig.project_name}-kubernetes-node`,
8282
{
8383
ami: projectConfig.ami,
@@ -86,12 +86,21 @@ const kubernetesNode = new aws.ec2.Instance(
8686
associatePublicIpAddress: true,
8787
vpcSecurityGroupIds: [stageSg.id, prodSg.id],
8888
keyName: keyPair.keyName,
89-
userData: `
90-
#!/bin/bash
91-
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
92-
sudo dpkg -i minikube_latest_amd64.deb
93-
minikube addons enable ingress
94-
`,
89+
userData: pulumi.interpolate`#!/bin/bash
90+
echo "Installing Docker..."
91+
curl -fsSL https://get.docker.com -o get-docker.sh
92+
sh get-docker.sh
93+
sudo usermod -aG docker $USER
94+
newgrp docker
95+
rm get-docker.sh
96+
97+
echo "Installing Minikube..."
98+
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
99+
sudo dpkg -i minikube_latest_amd64.deb
100+
minikube start --driver=docker
101+
minikube addons enable ingress
102+
103+
`,
95104
tags: {
96105
...projectConfig.tags,
97106
Name: `${projectConfig.project_name}-kubernetes-node`,
@@ -108,13 +117,13 @@ new aws.route53.Record(`${projectConfig.project_name}-a-record`, {
108117
name: projectConfig.project_domain,
109118
type: aws.route53.RecordType.A,
110119
ttl: 30,
111-
records: [kubernetesNode.publicIp],
120+
records: [node.publicIp],
112121
});
113122

114123
export const resources = {
115124
sshKeys: {
116125
privateKey: privateKey.privateKeyOpenssh,
117126
publicKey: privateKey.publicKeyOpenssh,
118127
},
119-
nodeIp: kubernetesNode.publicIp,
128+
nodeIp: node.publicIp,
120129
};

infrastructure/docker/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ events {
55
http {
66

77
upstream api {
8-
server api:3000;
8+
server api:3000;
99
}
1010

1111
server {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v2
2+
name: api
3+
description: NodeJS API application chart
4+
type: application
5+
version: 0.0.1
6+
appVersion: "0.0.1"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "api.fullname" . }}
5+
labels:
6+
app: {{ include "api.name" . }}
7+
spec:
8+
replicas: {{ .Values.replicaCount }}
9+
selector:
10+
matchLabels:
11+
app: {{ include "api.name" . }}
12+
template:
13+
metadata:
14+
labels:
15+
app: {{ include "api.name" . }}
16+
spec:
17+
containers:
18+
- name: {{ include "api.name" . }}
19+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
20+
ports:
21+
- containerPort: 3000
22+
resources:
23+
{{- toYaml .Values.resources | nindent 12 }}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: {{ include "api.fullname" . }}
5+
labels:
6+
app: {{ include "api.name" . }}
7+
annotations:
8+
traefik.ingress.kubernetes.io/router.entrypoints: web
9+
traefik.ingress.kubernetes.io/router.tls: "true"
10+
spec:
11+
rules:
12+
- host: {{ .Values.ingress.host | quote }}
13+
http:
14+
paths:
15+
- path: /
16+
pathType: Prefix
17+
backend:
18+
service:
19+
name: {{ include "api.fullname" . }}
20+
port:
21+
number: {{ .Values.service.port | default 80 }}
22+
tls:
23+
- hosts:
24+
- {{ .Values.ingress.host | quote }}
25+
secretName: {{ .Values.ingress.tlsSecret | quote }}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: {{ include "api.fullname" . }}-migrations
5+
labels:
6+
app: {{ include "api.name" . }}
7+
spec:
8+
template:
9+
spec:
10+
restartPolicy: Never
11+
containers:
12+
- name: migrations
13+
image: "{{ .Values.migrations.image.repository }}:{{ .Values.migrations.image.tag }}"
14+
envFrom:
15+
- secretRef:
16+
name: {{ .Values.migrations.envSecretName }}
17+
volumeMounts:
18+
- name: ssl-certs
19+
mountPath: /migrations/ssl
20+
readOnly: true
21+
volumes:
22+
- name: ssl-certs
23+
secret:
24+
secretName: {{ .Values.migrations.sslSecretName }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "api.fullname" . }}
5+
labels:
6+
app: {{ include "api.name" . }}
7+
spec:
8+
type: {{ .Values.service.type | default "ClusterIP" }}
9+
ports:
10+
- port: {{ .Values.service.port | default 80 }}
11+
targetPort: 3000
12+
protocol: TCP
13+
name: http
14+
selector:
15+
app: {{ include "api.name" . }}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
replicaCount: 1
2+
3+
image:
4+
repository: ghcr.io/kesha123/nodejs-rest-api/api
5+
tag: b44e2d404186bab1789d0b5cee39f7bc38897293
6+
7+
service:
8+
type: ClusterIP
9+
port: 80
10+
11+
ingress:
12+
enabled: true
13+
host: nodejs-rest-api.innokentii-kozlov.com
14+
tls:
15+
- secretName: nodejs-rest-api-tls
16+
17+
resources:
18+
limits:
19+
cpu: 100m
20+
memory: 128Mi
21+
requests:
22+
cpu: 100m
23+
memory: 128Mi
24+
25+
migrations:
26+
image:
27+
repository: ghcr.io/kesha123/nodejs-rest-api/migrations
28+
tag: b44e2d404186bab1789d0b5cee39f7bc38897293
29+
envSecretName: postgres-credentials
30+
sslSecretName: migrations-ssl-certs

0 commit comments

Comments
 (0)