Skip to content

Commit 8681f75

Browse files
author
Dimitri Pommier
authored
Kubernetes integration (pawelmalak#80)
* chore(): skaffold * chore(): kubernetes integration * chore(skaffold): refine shokohsc profile * chore(): removed docker & kubernetes from database + stoppedApp pin option * Revert "chore(): removed docker & kubernetes from database + stoppedApp pin option" This reverts commit 5111c7a.
1 parent c1b61f9 commit 8681f75

24 files changed

+5571
-93
lines changed

.dockerignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
node_modules
22
github
33
public
4-
build.sh
4+
build.sh
5+
k8s
6+
skaffold.yaml

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@
5656
- Added 'warnings' to apps and bookmarks forms about supported url formats ([#5](https://github.com/pawelmalak/flame/issues/5))
5757

5858
### v1.0 (2021-06-08)
59-
Initial release of Flame - self-hosted startpage using Node.js on backend and React on frontend.
59+
Initial release of Flame - self-hosted startpage using Node.js on backend and React on frontend.

Dockerfile.dev

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM node:lts-alpine as build-front
2+
RUN apk add --no-cache curl
3+
WORKDIR /app
4+
COPY ./client .
5+
RUN npm install --production \
6+
&& npm run build
7+
8+
FROM node:lts-alpine
9+
WORKDIR /app
10+
RUN mkdir -p ./public
11+
COPY --from=build-front /app/build/ ./public
12+
13+
COPY package*.json ./
14+
RUN npm install
15+
COPY . .
16+
CMD ["npm", "run", "skaffold"]

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Flame is self-hosted startpage for your server. Its design is inspired (heavily)
2222
- TypeScript
2323
- Deployment
2424
- Docker
25+
- Kubernetes
2526

2627
## Development
2728

@@ -80,6 +81,13 @@ services:
8081
restart: unless-stopped
8182
```
8283
84+
#### Skaffold
85+
86+
```sh
87+
# use skaffold
88+
skaffold dev
89+
```
90+
8391
### Without Docker
8492

8593
Follow instructions from wiki: [Installation without Docker](https://github.com/pawelmalak/flame/wiki/Installation-without-docker)
@@ -170,6 +178,21 @@ labels:
170178
171179
And you must have activated the Docker sync option in the settings panel.
172180
181+
### Kubernetes integration
182+
183+
In order to use the Kubernetes integration, each ingress must have the following annotations:
184+
185+
```yml
186+
metadata:
187+
annotations:
188+
- flame.pawelmalak/type=application # "app" works too
189+
- flame.pawelmalak/name=My container
190+
- flame.pawelmalak/url=https://example.com
191+
- flame.pawelmalak/icon=icon-name # Optional, default is "kubernetes"
192+
```
193+
194+
And you must have activated the Kubernetes sync option in the settings panel.
195+
173196
### Custom CSS
174197
175198
> This is an experimental feature. Its behaviour might change in the future.

client/.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
REACT_APP_VERSION=1.6.3
1+
REACT_APP_VERSION=1.6.3

client/src/components/Settings/OtherSettings/OtherSettings.tsx

+17
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
5252
bookmarksSameTab: 0,
5353
searchSameTab: 0,
5454
dockerApps: 1,
55+
kubernetesApps: 1,
5556
unpinStoppedApps: 1
5657
});
5758

@@ -71,6 +72,7 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
7172
bookmarksSameTab: searchConfig('bookmarksSameTab', 0),
7273
searchSameTab: searchConfig('searchSameTab', 0),
7374
dockerApps: searchConfig('dockerApps', 0),
75+
kubernetesApps: searchConfig('kubernetesApps', 0),
7476
unpinStoppedApps: searchConfig('unpinStoppedApps', 0)
7577
});
7678
}, [props.loading]);
@@ -297,6 +299,21 @@ const OtherSettings = (props: ComponentProps): JSX.Element => {
297299
<option value={0}>False</option>
298300
</select>
299301
</InputGroup>
302+
303+
{/* KUBERNETES SETTINGS */}
304+
<h2 className={classes.SettingsSection}>Kubernetes</h2>
305+
<InputGroup>
306+
<label htmlFor='kubernetesApps'>Use Kubernetes Ingress API</label>
307+
<select
308+
id='kubernetesApps'
309+
name='kubernetesApps'
310+
value={formData.kubernetesApps}
311+
onChange={e => inputChangeHandler(e, true)}
312+
>
313+
<option value={1}>True</option>
314+
<option value={0}>False</option>
315+
</select>
316+
</InputGroup>
300317
<Button>Save changes</Button>
301318
</form>
302319
);

client/src/interfaces/Forms.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ export interface SettingsForm {
1919
bookmarksSameTab: number;
2020
searchSameTab: number;
2121
dockerApps: number;
22+
kubernetesApps: number;
2223
unpinStoppedApps: number;
2324
}

controllers/apps.js

+62
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { Sequelize } = require('sequelize');
66
const axios = require('axios');
77
const Logger = require('../utils/Logger');
88
const logger = new Logger();
9+
const k8s = require('@kubernetes/client-node');
910

1011
// @desc Create new app
1112
// @route POST /api/apps
@@ -51,6 +52,9 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
5152
const useDockerApi = await Config.findOne({
5253
where: { key: 'dockerApps' }
5354
});
55+
const useKubernetesApi = await Config.findOne({
56+
where: { key: 'kubernetesApps' }
57+
});
5458
const unpinStoppedApps = await Config.findOne({
5559
where: { key: 'unpinStoppedApps' }
5660
});
@@ -116,6 +120,64 @@ exports.getApps = asyncWrapper(async (req, res, next) => {
116120
}
117121
}
118122

123+
if (useKubernetesApi && useKubernetesApi.value == 1) {
124+
let ingresses = null;
125+
126+
try {
127+
const kc = new k8s.KubeConfig();
128+
kc.loadFromCluster();
129+
const k8sNetworkingV1Api = kc.makeApiClient(k8s.NetworkingV1Api);
130+
await k8sNetworkingV1Api.listIngressForAllNamespaces()
131+
.then((res) => {
132+
ingresses = res.body.items;
133+
});
134+
} catch {
135+
logger.log("Can't connect to the kubernetes api", 'ERROR');
136+
}
137+
138+
if (ingresses) {
139+
apps = await App.findAll({
140+
order: [[orderType, 'ASC']]
141+
});
142+
143+
ingresses = ingresses.filter(e => Object.keys(e.metadata.annotations).length !== 0);
144+
const kubernetesApps = [];
145+
for (const ingress of ingresses) {
146+
const annotations = ingress.metadata.annotations;
147+
148+
if (
149+
'flame.pawelmalak/name' in annotations &&
150+
'flame.pawelmalak/url' in annotations &&
151+
/^app/.test(annotations['flame.pawelmalak/type'])
152+
) {
153+
kubernetesApps.push({
154+
name: annotations['flame.pawelmalak/name'],
155+
url: annotations['flame.pawelmalak/url'],
156+
icon: annotations['flame.pawelmalak/icon'] || 'kubernetes'
157+
});
158+
}
159+
}
160+
161+
if (unpinStoppedApps && unpinStoppedApps.value == 1) {
162+
for (const app of apps) {
163+
await app.update({ isPinned: false });
164+
}
165+
}
166+
167+
for (const item of kubernetesApps) {
168+
if (apps.some(app => app.name === item.name)) {
169+
const app = apps.filter(e => e.name === item.name)[0];
170+
await app.update({ ...item, isPinned: true });
171+
} else {
172+
await App.create({
173+
...item,
174+
isPinned: true
175+
});
176+
}
177+
}
178+
}
179+
}
180+
119181
if (orderType == 'name') {
120182
apps = await App.findAll({
121183
order: [[Sequelize.fn('lower', Sequelize.col('name')), 'ASC']]

k8s/base/deployment.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
kind: Deployment
3+
apiVersion: apps/v1
4+
metadata:
5+
name: flame
6+
spec:
7+
selector:
8+
matchLabels:
9+
app: flame
10+
template:
11+
metadata:
12+
labels:
13+
app: flame
14+
spec:
15+
serviceAccountName: flame
16+
securityContext:
17+
fsGroup: 1000
18+
containers:
19+
- name: flame
20+
image: shokohsc/flame
21+
ports:
22+
- name: http
23+
containerPort: 5005
24+
protocol: TCP
25+
readinessProbe:
26+
httpGet:
27+
path: /
28+
port: http

k8s/base/ingress.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
apiVersion: networking.k8s.io/v1
3+
kind: Ingress
4+
metadata:
5+
name: flame
6+
spec:
7+
rules:
8+
- host: flame.cluster.local
9+
http:
10+
paths:
11+
- path: /
12+
pathType: Prefix
13+
backend:
14+
service:
15+
name: flame
16+
port:
17+
number: 80

k8s/base/kustomization.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
namespace: flame
4+
resources:
5+
- namespace.yaml
6+
- deployment.yaml
7+
- service.yaml
8+
- ingress.yaml
9+
- rbac.yaml

k8s/base/namespace.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: flame
6+
labels:
7+
namespace: flame
8+
goldilocks.fairwinds.com/enabled: "true"

k8s/base/rbac.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: flame
6+
---
7+
kind: ClusterRole
8+
apiVersion: rbac.authorization.k8s.io/v1
9+
metadata:
10+
name: flame
11+
rules:
12+
- apiGroups: ["networking.k8s.io"]
13+
resources: ["ingresses"]
14+
verbs: ["get", "list", "watch"]
15+
---
16+
apiVersion: rbac.authorization.k8s.io/v1
17+
kind: ClusterRoleBinding
18+
metadata:
19+
name: flame
20+
subjects:
21+
- kind: ServiceAccount
22+
name: flame
23+
roleRef:
24+
apiGroup: rbac.authorization.k8s.io
25+
kind: ClusterRole
26+
name: flame

k8s/base/service.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: flame
6+
labels:
7+
app: flame
8+
spec:
9+
type: ClusterIP
10+
ports:
11+
- port: 80
12+
targetPort: http
13+
protocol: TCP
14+
name: http
15+
selector:
16+
app: flame

k8s/overlays/shokohsc/deployment.yaml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
kind: Deployment
3+
apiVersion: apps/v1
4+
metadata:
5+
name: flame
6+
spec:
7+
selector:
8+
matchLabels:
9+
app: flame
10+
template:
11+
metadata:
12+
labels:
13+
app: flame
14+
spec:
15+
serviceAccountName: flame-dev
16+
securityContext:
17+
fsGroup: 1000
18+
containers:
19+
- name: flame
20+
image: shokohsc/flame
21+
command:
22+
- npm
23+
args:
24+
- run
25+
- skaffold
26+
env:
27+
- name: NODE_ENV
28+
value: development
29+
ports:
30+
- name: http
31+
containerPort: 5005
32+
protocol: TCP
33+
readinessProbe:
34+
httpGet:
35+
path: /
36+
port: http

k8s/overlays/shokohsc/ingress.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
apiVersion: networking.k8s.io/v1
3+
kind: Ingress
4+
metadata:
5+
name: flame
6+
annotations:
7+
kubernetes.io/ingress.class: nginx
8+
cert-manager.io/cluster-issuer: ca-cluster-issuer
9+
flame.pawelmalak/name: flame
10+
flame.pawelmalak/url: dev.flame.shokohsc.home
11+
flame.pawelmalak/type: app
12+
flame.pawelmalak/icon: fire
13+
spec:
14+
rules:
15+
- host: dev.flame.shokohsc.home
16+
http:
17+
paths:
18+
- path: /
19+
pathType: Prefix
20+
backend:
21+
service:
22+
name: flame
23+
port:
24+
number: 80
25+
tls:
26+
- hosts:
27+
- dev.flame.shokohsc.home
28+
secretName: flame-cert
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
namespace: flame-dev
4+
resources:
5+
- namespace.yaml
6+
- deployment.yaml
7+
- service.yaml
8+
- ingress.yaml
9+
- rbac.yaml

0 commit comments

Comments
 (0)