-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk8s.yml
127 lines (125 loc) · 3.08 KB
/
k8s.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
apiVersion: apps/v1
kind: Deployment
metadata:
name: miragex-app-controller
spec:
replicas: 1
selector:
matchLabels:
name: miragex-app-controller
template:
metadata:
labels:
name: miragex-app-controller
spec:
serviceAccountName: miragex-app-controller-sa
volumes:
- name: app-volume
emptyDir: {}
initContainers:
- name: git-clone
image: alpine/git:latest
command: ["sh", "-c"]
args:
- |
# .git ディレクトリが既にあれば pull, なければ clone
if [ -d "/app/.git" ]; then
echo "Repository already exists. Pulling latest changes..."
cd /app
git pull
else
echo "Repository not found. Cloning..."
git clone https://github.com/rassi0429/miragex.app /app
fi
volumeMounts:
- name: "app-volume"
mountPath: "/app"
containers:
- name: node-bot
image: node:22-alpine
imagePullPolicy: Always
workingDir: /app
command: ["sh", "-c"]
args: ['npm install && npm run build && npm run start']
volumeMounts:
- name: "app-volume"
mountPath: "/app"
ports:
- containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: miragex-app-controller
labels:
app: miragex-app-controller
spec:
type: ClusterIP
selector:
name: miragex-app-controller
ports:
- port: 80
targetPort: 3000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: miragex-app-controller
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: neorb.app
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: miragex-app-controller
port:
number: 80
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: miragex-app-controller-cluster-role
rules:
# Deployments
- apiGroups: ["apps"]
resources:
- deployments
verbs:
- "*"
# Pods, Services
- apiGroups: [""]
resources:
- pods
- services
verbs:
- "*"
# Ingress
- apiGroups: ["networking.k8s.io"]
resources:
- ingresses
verbs:
- "*"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: miragex-app-controller-cluster-role-binding
subjects:
- kind: ServiceAccount
name: miragex-app-controller-sa # 紐付けたい ServiceAccount 名
namespace: default # 上記 ServiceAccount の Namespace
roleRef:
kind: ClusterRole
name: miragex-app-controller-cluster-role # 上で作成した ClusterRole
apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: miragex-app-controller-sa
namespace: default