From 626b35ac8421e8377f01f98b62b1bebf73135669 Mon Sep 17 00:00:00 2001 From: ivamp Date: Thu, 18 Jul 2024 00:41:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E5=92=8C=E9=83=A8=E7=BD=B2=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 19 +++++++++++ manifest.yaml | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 Dockerfile create mode 100644 manifest.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3e8033f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +# Use the official Golang image as a base image +FROM golang:1.22.5-alpine + +# Set the working directory inside the container +WORKDIR /app + +# Copy the Go application into the container +COPY . . + +RUN go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn + +# Build the Go application +RUN go build -ldflags="-s -w" -o app main.go + + +FROM alpine:latest +COPY --from=0 /app/app /app/app + +CMD ["/app/app"] \ No newline at end of file diff --git a/manifest.yaml b/manifest.yaml new file mode 100644 index 0000000..c77ba6b --- /dev/null +++ b/manifest.yaml @@ -0,0 +1,92 @@ +# deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: k8s-web-status + namespace: websites + labels: + app: web-status +spec: + replicas: 1 + selector: + matchLabels: + app: web-status + template: + metadata: + labels: + app: web-status + spec: + serviceAccountName: web-status-sa + containers: + - name: web-status + image: registry.leafdev.top/leaf/go-k8s-deployment-status:v0.0.1 + imagePullPolicy: Always + ports: + - containerPort: 8080 + env: + - name: KUBERNETES_SERVICE_HOST + value: "kubernetes.default.svc" + - name: KUBERNETES_SERVICE_PORT + value: "443" + envFrom: + - configMapRef: + name: web-status-configmap +--- +# configMap.yaml +apiVersion: v1 +kind: ConfigMap +metadata: + name: web-status-configmap + namespace: websites + labels: + app: web-status +data: + NAMESPACES: "websites" +--- +# service.yaml +apiVersion: v1 +kind: Service +metadata: + name: web-status-service + namespace: websites +spec: + selector: + app: web-status + ports: + - protocol: TCP + port: 80 + targetPort: 8080 + type: ClusterIP +--- +# serviceaccount.yaml +apiVersion: v1 +kind: ServiceAccount +metadata: + name: web-status-sa + namespace: websites +--- +# role.yaml +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + namespace: websites + name: web-status-role +rules: + - apiGroups: ["", "apps", "extensions"] + resources: ["deployments"] + verbs: ["get", "list"] +--- +# rolebinding.yaml +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: web-status-rb + namespace: websites +subjects: + - kind: ServiceAccount + name: web-status-sa + namespace: websites +roleRef: + kind: Role + name: web-status-role + apiGroup: rbac.authorization.k8s.io