Skip to content

Commit 45098e1

Browse files
committed
Add k8s deploy.yaml and support docker images
1 parent 4f2c0f4 commit 45098e1

File tree

3 files changed

+113
-5
lines changed

3 files changed

+113
-5
lines changed

Dockerfile

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
FROM golang:1.24.0 as builder
1+
FROM --platform=$BUILDPLATFORM golang:1.24.0 as builder
22

3-
WORKDIR /workspace
3+
WORKDIR /app
44
ENV GOPROXY=https://goproxy.cn,direct
55

6+
COPY go.mod go.sum ./
7+
RUN go mod download
8+
69
COPY . .
710

8-
#### Build
9-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build .
1011

11-
CMD ["/workspace/kube-node-metrics"]
12+
ARG TARGETARCH
13+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -o kube-node-metrics .
14+
15+
FROM scratch
16+
WORKDIR /
17+
COPY --from=builder /app/kube-node-metrics .
18+
19+
EXPOSE 19191
20+
21+
CMD ["/kube-node-metrics"]

Makefile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.PHONY:
2+
build:
3+
go fmt ./...
4+
go mod tidy
5+
go vet ./...
6+
go build .
7+
8+
.PHONY:
9+
build-docker:
10+
docker buildx build --platform linux/amd64,linux/arm64 \
11+
-t xiaozongyang/kube-node-metrics:latest \
12+
--push .
13+
14+
.PHONY:
15+
clean:
16+
rm kube-node-metrics

deploy.yaml

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: kube-node-metrics
5+
namespace: default
6+
7+
---
8+
apiVersion: rbac.authorization.k8s.io/v1
9+
kind: ClusterRole
10+
metadata:
11+
name: kube-node-metrics
12+
rules:
13+
- apiGroups: [""]
14+
resources: ["nodes"]
15+
verbs: ["list", "watch"]
16+
- apiGroups: [""]
17+
resources: ["pods"]
18+
verbs: ["list", "watch"]
19+
---
20+
apiVersion: rbac.authorization.k8s.io/v1
21+
kind: ClusterRoleBinding
22+
metadata:
23+
name: kube-node-metrics
24+
roleRef:
25+
apiGroup: rbac.authorization.k8s.io
26+
kind: ClusterRole
27+
name: kube-node-metrics
28+
subjects:
29+
- kind: ServiceAccount
30+
name: kube-node-metrics
31+
namespace: default
32+
33+
---
34+
apiVersion: apps/v1
35+
kind: Deployment
36+
metadata:
37+
name: kube-node-metrics
38+
namespace: default
39+
spec:
40+
replicas: 1
41+
selector:
42+
matchLabels:
43+
app: kube-node-metrics
44+
template:
45+
metadata:
46+
labels:
47+
app: kube-node-metrics
48+
spec:
49+
serviceAccountName: kube-node-metrics
50+
containers:
51+
- name: kubep-node-metrics
52+
image: docker.io/xiaozongyang/kube-node-metrics:latest
53+
env:
54+
- name: FULL_SYNC_INTERVAL
55+
value: "2m"
56+
ports:
57+
- containerPort: 19191
58+
name: metrics
59+
resources:
60+
limits:
61+
memory: "2Gi"
62+
cpu: "2000m"
63+
requests:
64+
memory: "64Mi"
65+
cpu: "50m"
66+
tolerations:
67+
- operator: Exists
68+
---
69+
apiVersion: v1
70+
kind: Service
71+
metadata:
72+
name: kube-node-metrics
73+
namespace: default
74+
labels:
75+
app: kube-node-metrics
76+
spec:
77+
selector:
78+
app: kube-node-metrics
79+
ports:
80+
- port: 19191
81+
targetPort: 19191
82+
name: metrics

0 commit comments

Comments
 (0)