From b0012f3ee7e9d1298c0b4a17738eb1b88e903c90 Mon Sep 17 00:00:00 2001 From: ZhangQiuSheng Date: Thu, 3 Jan 2019 14:13:18 +0800 Subject: [PATCH 1/2] add k8s deploy resource --- k8s-deploy/Dockerfile-agent | 17 ++++++++++++ k8s-deploy/gocron-agent.yml | 38 ++++++++++++++++++++++++++ k8s-deploy/gocron-server.yml | 36 ++++++++++++++++++++++++ k8s-deploy/mysql-st.yaml | 53 ++++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 k8s-deploy/Dockerfile-agent create mode 100644 k8s-deploy/gocron-agent.yml create mode 100644 k8s-deploy/gocron-server.yml create mode 100644 k8s-deploy/mysql-st.yaml diff --git a/k8s-deploy/Dockerfile-agent b/k8s-deploy/Dockerfile-agent new file mode 100644 index 0000000..96f5f8b --- /dev/null +++ b/k8s-deploy/Dockerfile-agent @@ -0,0 +1,17 @@ +FROM alpine:3.7 + +ENV GOCRON_AGENT_VERSION=v1.5 + +RUN apk add --no-cache ca-certificates tzdata bash \ + && mkdir -p /app \ + && wget -P /tmp https://github.com/ouqiang/gocron/releases/download/${GOCRON_AGENT_VERSION}/gocron-node-${GOCRON_AGENT_VERSION}-linux-amd64.tar.gz \ + && cd /tmp \ + && tar zvxf gocron-node-${GOCRON_AGENT_VERSION}-linux-amd64.tar.gz \ + && mv /tmp/gocron-node-linux-amd64/gocron-node /app \ + && rm -rf /tmp/* \ + && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime + +WORKDIR /app +EXPOSE 5921 + +ENTRYPOINT ["/app/gocron-node", "-allow-root"] diff --git a/k8s-deploy/gocron-agent.yml b/k8s-deploy/gocron-agent.yml new file mode 100644 index 0000000..e1afc26 --- /dev/null +++ b/k8s-deploy/gocron-agent.yml @@ -0,0 +1,38 @@ +apiVersion: extensions/v1beta1 +kind: DaemonSet +metadata: + name: gocron-agent + namespace: kube-system +spec: + selector: + matchLabels: + daemon: gocron-agent + template: + metadata: + labels: + daemon: gocron-agent + name: gocron-agent + spec: + containers: + - name: gocron-agent + image: crontab-agent:0.5 + imagePullPolicy: IfNotPresent + ports: + - containerPort: 5921 + hostPort: 5921 + name: gocron-agent + protocol: TCP + resources: {} + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumeMounts: + - mountPath: /var/log + name: syslog + hostNetwork: true + hostPID: true + restartPolicy: Always + volumes: + - hostPath: + path: /var/log + type: Directory + name: syslog \ No newline at end of file diff --git a/k8s-deploy/gocron-server.yml b/k8s-deploy/gocron-server.yml new file mode 100644 index 0000000..989eb21 --- /dev/null +++ b/k8s-deploy/gocron-server.yml @@ -0,0 +1,36 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: gocron + labels: + app: gocron +spec: + ports: + - port: 5920 + name: gocron + type: NodePort + selector: + app: gocron +--- +apiVersion: apps/v1beta1 +kind: Deployment +metadata: + labels: + name: gocron + name: gocron +spec: + replicas: 1 + selector: + matchLabels: + app: gocron + template: + metadata: + labels: + app: gocron + spec: + containers: + - name: gocron + image: ouqg/gocron + ports: + - containerPort: 5920 \ No newline at end of file diff --git a/k8s-deploy/mysql-st.yaml b/k8s-deploy/mysql-st.yaml new file mode 100644 index 0000000..ed48e9a --- /dev/null +++ b/k8s-deploy/mysql-st.yaml @@ -0,0 +1,53 @@ +--- +apiVersion: v1 +kind: Service +metadata: + name: mysql + #namespace: storage + labels: + app: mysql +spec: + ports: + - port: 3306 + name: mysql + clusterIP: None + selector: + app: mysql +--- +apiVersion: apps/v1beta1 +kind: StatefulSet +metadata: + name: mysql + #namespace: storage +spec: + serviceName: "mysql" + replicas: 1 + template: + metadata: + labels: + app: mysql + spec: + terminationGracePeriodSeconds: 10 + containers: + - name: mysql + image: mysql:5.6 + env: + - name: MYSQL_ROOT_PASSWORD + value: password + - name: MYSQL_DATABASE + value: crontab + ports: + - containerPort: 3306 + name: mysql + volumeMounts: + - name: mysql-vol + mountPath: /var/lib/mysql + volumeClaimTemplates: + - metadata: + name: mysql-vol + spec: + storageClassName: rbd # 需要storageClassName + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: 100Gi \ No newline at end of file From bdd19955a6acdcf8d6d64c8f3d188981c09eeb0d Mon Sep 17 00:00:00 2001 From: ZhangQiuSheng Date: Wed, 16 Jan 2019 14:00:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=94=B9=E5=8F=98=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=96=B9=E5=BC=8F=EF=BC=8C=E6=8A=8A=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=AD=98=E5=88=B0=E5=A4=96=E7=BD=AE=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- k8s-deploy/gocron-server.yml | 36 ------------------------- k8s-deploy/gocron-st.yml | 51 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 36 deletions(-) delete mode 100644 k8s-deploy/gocron-server.yml create mode 100644 k8s-deploy/gocron-st.yml diff --git a/k8s-deploy/gocron-server.yml b/k8s-deploy/gocron-server.yml deleted file mode 100644 index 989eb21..0000000 --- a/k8s-deploy/gocron-server.yml +++ /dev/null @@ -1,36 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - name: gocron - labels: - app: gocron -spec: - ports: - - port: 5920 - name: gocron - type: NodePort - selector: - app: gocron ---- -apiVersion: apps/v1beta1 -kind: Deployment -metadata: - labels: - name: gocron - name: gocron -spec: - replicas: 1 - selector: - matchLabels: - app: gocron - template: - metadata: - labels: - app: gocron - spec: - containers: - - name: gocron - image: ouqg/gocron - ports: - - containerPort: 5920 \ No newline at end of file diff --git a/k8s-deploy/gocron-st.yml b/k8s-deploy/gocron-st.yml new file mode 100644 index 0000000..b41fc54 --- /dev/null +++ b/k8s-deploy/gocron-st.yml @@ -0,0 +1,51 @@ +# 改为用StatefulSet部署,把配置目录挂载到外置存储,以防container down后重启 +# 如果使用历史数据库,需要先配置安装,然后在conf目录下创建install.lock文件,最后重启进程即可 +# +--- +apiVersion: v1 +kind: Service +metadata: + name: gocron + labels: + app: gocron +spec: + ports: + - port: 5920 + name: gocron + type: NodePort + selector: + app: gocron +--- +apiVersion: apps/v1beta1 +kind: StatefulSet +metadata: + name: gocron +spec: + serviceName: "gocron" + replicas: 1 + template: + metadata: + labels: + app: gocron + spec: + securityContext: + fsGroup: 1000 + terminationGracePeriodSeconds: 10 + containers: + - name: gocron + image: ouqg/gocron:latest + ports: + - containerPort: 5920 + name: gocron + volumeMounts: + - name: gocron-vol + mountPath: /app/conf + volumeClaimTemplates: + - metadata: + name: gocron-vol + spec: + storageClassName: rbd + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: 100Mi \ No newline at end of file