当前位置: 首页 > 工具软件 > Spinnaker > 使用案例 >

Spinnaker微服务如何自建

范文昌
2023-12-01

Spinnaker采用了微服务体系,而对于整套微服务体系的搭建官方是推荐采用halyard来搭建的。

Halyard对于spinnaker的黑盒使用者比较友好,把对spinnaker的安装、部署、配置、管理等都封装成命令(其实命令也是够复杂的),但对于具有研发基础或者说对于spinnaker比较了解的人来说这种方式有点本末倒置了,本篇在原理上介绍下如何绕过halyard自己搭建spinnaker的微服务。

从原理上来讲spinnaker分为“软件包启动”和“源码启动”,从运行环境来讲spinnaker部署分为“虚机部署”和“容器云”部署。

非deck服务(java):

nohup sh -c "./gradlew --daemon 2>&1 | tee /tmp/clouddriver.log | cat >/dev/null" >/dev/null &

deck服务(angular.js):

yarn install
nohup yarn run start &

软件包启动:

直接运行编译包install中bin里的启动文件,启动迅速,缺点是修改代码后需要重新发布。

非deck服务:

${SpinnakerHome}/clouddriver/bin/clouddriver

deck服务:

${SpinnakerHome}/deck/start.sh

开发推荐用源码启动方式, 生产推荐用软件包启动方式,以下对部署的讲解都是基于软件包的。

无论哪种部署方式,整体思路都是类似的,以虚机部署为例,分为如下几步:

1 准备语言环境

  非deck服务(也就是java环境):

sudo apt-get install openjdk-8-jdk
##设置JAVA_HOME和PATH

 deck服务:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
source .bashrc
nvm install v10.15.3
npm install -g yarn
npm install -g pm2

 

2 部署软件包

  将java项目的install内容和deck项目根目录下的内容拷贝到机器中。

3 部署依赖的组件

  为某些特殊服务节点安装运行依赖的组件,为rosco节点安装packer,为clouddriver节点安装kubectl。

4 修改配置文件

  这个没什么好说的,应用启动用到的各种配置:云平台账号、redis配置、CI集成相关配置。

5 设置开机启动和守护

  Java系依赖supervisor,deck依赖pm2,部署在容器云的话依赖replicaset

容器云部署更便捷,但准备工作更繁琐,需要准备镜像Dockerfile和执行时的manifest,以rosco为例。

DockerFile:

#指定镜像
FROM hub.imgo.tv/spinnaker/basic:v1.0

#作者信息
MAINTAINER YeJingtao <jingtao@mgtv.com>

#准备目录
RUN ["mkdir", "-p", "/opt/spinnaker/config"]

#复制软件包
COPY ./rosco.tar /opt
COPY ./packer.tar /opt
COPY ./packer /usr/bin
COPY ./packer-builder-huaweicloud-ecs /usr/bin

#添加执行权限
RUN ["chmod", "+x", "/usr/bin/packer"]
RUN ["chmod", "+x", "/usr/bin/packer-builder-huaweicloud-ecs"]

#解压软件包
WORKDIR /opt
RUN ["tar", "-xvf", "rosco.tar"]
RUN ["tar", "-xvf", "packer.tar"]

#完成日志
RUN echo "rosco docker file is ok"

service.yml:

apiVersion: v1
kind: Service
metadata:
  annotations:
    field.cattle.io/creatorId: u-xridxugrsm
    field.cattle.io/ipAddresses: "null"
    field.cattle.io/targetDnsRecordIds: "null"
    field.cattle.io/targetWorkloadIds: "null"
  creationTimestamp: "2021-05-21T07:39:29Z"
  labels:
    cattle.io/creator: norman
  name: spinnaker-rosco
  namespace: devops
  resourceVersion: "214861147"
  selfLink: /api/v1/namespaces/devops/services/spinnaker-rosco
  uid: 5bc17ac4-1270-48da-9655-864ef8bd08e5
spec:
  clusterIP: None
  ports:
  - name: default
    port: 8087
    protocol: TCP
    targetPort: 8087
  selector:
    spinnaker.service: rosco
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}

configMap.yml

apiVersion: v1
data:
  rosco.yml: |-
    spectator:
      applicationName: ${spring.application.name}
      webEndpoint:
        enabled: false
kind: ConfigMap
metadata:
  annotations:
    field.cattle.io/creatorId: u-xridxugrsm
  creationTimestamp: "2021-05-21T11:35:51Z"
  labels:
    cattle.io/creator: norman
  name: spinnaker-rosco-configmap
  namespace: devops
  resourceVersion: "214857661"
  selfLink: /api/v1/namespaces/devops/configmaps/spinnaker-rosco-configmap
  uid: f1d9522c-7450-462a-a012-f7dbf4ae54d2

deploy.yml

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  annotations:
    artifact.spinnaker.io/location: devops
    artifact.spinnaker.io/name: spinnaker-rosco
    artifact.spinnaker.io/type: kubernetes/deployment
    moniker.spinnaker.io/application: spinnaker
    moniker.spinnaker.io/cluster: spinnaker-rosco
    strategy.spinnaker.io/max-version-history: '1'
    strategy.spinnaker.io/use-source-capaspinnakerty: 'true'
  labels:
    app.kubernetes.io/managed-by: spinnaker
    app.kubernetes.io/name: spinnaker-rosco
  name: spinnaker-rosco
  namespace: devops
spec:
  replicas: 1
  selector:
    matchLabels:
      spinnaker.service: rosco
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      annotations:
        artifact.spinnaker.io/location: devops
        artifact.spinnaker.io/name: spinnaker-rosco
        artifact.spinnaker.io/type: kubernetes/deployment
        moniker.spinnaker.io/application: spinnaker
        moniker.spinnaker.io/cluster: spinnaker-rosco
      labels:
        app.kubernetes.io/managed-by: spinnaker
        app.kubernetes.io/name: spinnaker-rosco
        spinnaker.service: rosco
        task: monitoring
    spec:
      containers:
        - command:
            - /opt/rosco/bin/rosco
          image: 'hub.imgo.tv/spinnaker/rosco:${ parameters.image_version}'
          imagePullPolicy: IfNotPresent
          livenessProbe:
            initialDelaySeconds: 300
            tcpSocket:
              port: 8087
            timeoutSeconds: 60
          name: spinnaker-rosco
          volumeMounts:
            - mountPath: /opt/spinnaker/config/rosco.yml
              name: app-conf
              subPath: rosco.yml
            - mountPath: /opt/spinnaker/config/spinnaker.yml
              name: main-conf
              subPath: spinnaker.yml
            - mountPath: /opt/spinnaker/config/packer
              name: packer-temp
      volumes:
        - configMap:
            items:
              - key: rosco.yml
                path: rosco.yml
            name: spinnaker-rosco-configmap
          name: app-conf
        - configMap:
            items:
              - key: spinnaker.yml
                path: spinnaker.yml
            name: spinnaker-main-configmap
          name: main-conf
        - name: packer-temp
          persistentVolumeClaim:
            claimName: spinnaker-pvc

 

 类似资料: