Skip to content

Commit a335bb5

Browse files
committed
add k8s deployment
1 parent bc04972 commit a335bb5

4 files changed

Lines changed: 80 additions & 5 deletions

File tree

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Usage:
22
#
33
# Build image:
4-
# docker build -t jojozhuang/text-compare-angular .
4+
# docker build -t jojozhuang/text-compare-angular-arm . -f Dockerfile-ARM
55
#
66
# Run image (on localhost:12010):
7-
# docker run -d --name text-compare -p 12010:80 jojozhuang/text-compare-angular
7+
# docker run -d --name text-compare -p 12010:80 jojozhuang/text-compare-angular-arm
88
#
99
# Run image as virtual host (read more: https://github.com/nginx-proxy/nginx-proxy):
1010
# docker run -e VIRTUAL_HOST=text-compare.your-domain.com --name text-compare jojozhuang/text-compare-angular
1111

1212
# Stage 1, based on Node.js, to build and compile Angular
1313

14-
FROM node:15.12.0-alpine as builder
14+
FROM node:16.10.0-alpine as builder
1515

1616
WORKDIR /ng-app
1717

@@ -22,7 +22,7 @@ RUN npm ci --quiet && npm run build-nas
2222

2323
# Stage 2, based on Nginx, to have only the compiled app, ready for production with Nginx
2424

25-
FROM nginx:1.19.8-alpine
25+
FROM arm64v8/nginx
2626

2727
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
2828

Dockerfile-old

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Usage:
2+
#
3+
# Build image:
4+
# docker build -t jojozhuang/text-compare-angular .
5+
#
6+
# Run image (on localhost:12010):
7+
# docker run -d --name text-compare -p 12010:80 jojozhuang/text-compare-angular
8+
#
9+
# Run image as virtual host (read more: https://github.com/nginx-proxy/nginx-proxy):
10+
# docker run -e VIRTUAL_HOST=text-compare.your-domain.com --name text-compare jojozhuang/text-compare-angular
11+
12+
# Stage 1, based on Node.js, to build and compile Angular
13+
14+
FROM node:16.10.0-alpine as builder
15+
16+
WORKDIR /ng-app
17+
18+
COPY package*.json tsconfig*.json angular.json ./
19+
COPY ./src ./src
20+
21+
RUN npm ci --quiet && npm run build-nas
22+
23+
# Stage 2, based on Nginx, to have only the compiled app, ready for production with Nginx
24+
25+
FROM nginx:1.19.8-alpine
26+
27+
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
28+
29+
## From ‘builder’ stage copy over the artifacts in dist folder to default nginx public folder
30+
COPY --from=builder /ng-app/dist /usr/share/nginx/html

k8s/text-compare.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Setup loocally
2+
# 1. Build image for ARM platform
3+
# docker build -t text-compare-angular-arm . -f Dockerfile-ARM
4+
# 2. Deploy to k8s:
5+
# kubectl apply -f k8s/text-compare.yaml
6+
# 3. Create service in minikube:
7+
# minikube service text-compare-service
8+
# 4. Access the url from step 3.
9+
10+
apiVersion: apps/v1
11+
kind: Deployment
12+
metadata:
13+
name: text-compare-deployment
14+
labels:
15+
app: text-compare
16+
spec:
17+
replicas: 1
18+
selector:
19+
matchLabels:
20+
app: text-compare
21+
template:
22+
metadata:
23+
labels:
24+
app: text-compare
25+
spec:
26+
containers:
27+
- name: text-compare
28+
image: jojozhuang/text-compare-angular
29+
ports:
30+
- containerPort: 80
31+
---
32+
apiVersion: v1
33+
kind: Service
34+
metadata:
35+
name: text-compare-service
36+
spec:
37+
selector:
38+
app: text-compare
39+
type: LoadBalancer # assign an external IP address to accept external request
40+
ports:
41+
- protocol: TCP
42+
port: 12011
43+
targetPort: 80
44+
nodePort: 31000 # must be between 30000 and 32767

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)