ci: add Hugo blog CI/CD to k3s
Some checks failed
Deploy Hugo Blog to k3s / build-and-deploy (push) Failing after 4m5s

- Enable Gitea Container Registry
- Dockerfile: nginx:alpine serving hugo public/
- Gitea Actions: build & push image + deploy to k3s
- k8s manifests: namespace hugo, deployment, service, ingress
- RBAC: allow runner to update deployments in hugo ns
- .gitignore: add public/ (CI builds it)
This commit is contained in:
luochen570
2026-05-31 03:09:14 +08:00
parent e0d7f07c24
commit d05adc2ffe
22 changed files with 185 additions and 1295 deletions

View File

@@ -0,0 +1,41 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: hugo-blog
namespace: hugo
labels:
app: hugo-blog
spec:
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
selector:
matchLabels:
app: hugo-blog
template:
metadata:
labels:
app: hugo-blog
spec:
containers:
- name: nginx
image: git.luochen570.cn/luochen570/hugo-blog:latest
imagePullPolicy: Always
ports:
- containerPort: 80
name: http
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 15
periodSeconds: 20

24
deploy/hugo-ingress.yaml Normal file
View File

@@ -0,0 +1,24 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hugo-blog
namespace: hugo
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
ingressClassName: traefik
rules:
- host: hugo.test.luochen570.cn
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hugo-blog
port:
number: 80
tls:
- hosts:
- hugo.test.luochen570.cn
secretName: hugo-test-luochen570-cn-tls

View File

@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: hugo

26
deploy/hugo-rbac.yaml Normal file
View File

@@ -0,0 +1,26 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: hugo-deployer
namespace: hugo
rules:
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch", "patch", "update"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: hugo-deployer-binding
namespace: hugo
subjects:
- kind: ServiceAccount
name: default
namespace: gitea-runner
roleRef:
kind: Role
name: hugo-deployer
apiGroup: rbac.authorization.k8s.io

16
deploy/hugo-service.yaml Normal file
View File

@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: hugo-blog
namespace: hugo
labels:
app: hugo-blog
spec:
type: ClusterIP
ports:
- port: 80
targetPort: 80
protocol: TCP
name: http
selector:
app: hugo-blog