美文网首页K8技术中台
k8s:部署sentinel-dashboard

k8s:部署sentinel-dashboard

作者: 前浪浪奔浪流 | 来源:发表于2021-11-12 10:21 被阅读0次

    1、构建镜像(DockerFile)
    2、本地测试镜像(docker run)
    3、上传至harbor(192.168.100.204:80)
    4、创建StatefulSet和service

    StatefulSet
    RC、Deployment、DaemonSet都是面向无状态的服务,它们所管理的Pod的IP、名字,启停顺序等都是随机的,而StatefulSet是什么?顾名思义,有状态的集合,管理所有有状态的服务,比如MySQL、MongoDB集群等。
    StatefulSet本质上是Deployment的一种变体,在v1.9版本中已成为GA版本,它为了解决有状态服务的问题,它所管理的Pod拥有固定的Pod名称,启停顺序,在StatefulSet中,Pod名字称为网络标识(hostname),还必须要用到共享存储。
    在Deployment中,与之对应的服务是service,而在StatefulSet中与之对应的headless service,headless service,即无头服务,与service的区别就是它没有Cluster IP,解析它的名称时将返回该Headless Service对应的全部Pod的Endpoint列表。
    除此之外,StatefulSet在Headless Service的基础上又为StatefulSet控制的每个Pod副本创建了一个DNS域名,这个域名的格式为:
    $(podname).(headless server name)
    FQDN:$(podname).(headless server name).namespace.svc.cluster.local
    

    https://blog.csdn.net/weixin_44729138/article/details/106054025
    5、通过serviceIP访问

    1、构建镜像(DockerFile)

    # 基础镜像
    FROM openjdk:8-jdk-alpine
    # 作者(可选)
    MAINTAINER fh
    # 设置时区
    ENV TZ=Asia/Shanghai
    RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
    ENV LC_ALL "zh_CN.UTF-8"
    # copy当前工程jar包至容器内
    COPY sentinel-dashboard-1.8.1.jar /tmp/sentinel-dashboard-1.8.1.jar
    # 运行jar包,设置环境变量 JAVA_OPTS,通过docker run -e JAVA_OPTS='xxxxx'传递参数,不能用 CMD [],读取不到变量
    CMD java ${JAVA_OPTS} -jar /tmp/sentinel-dashboard-1.8.1.jar
    

    构建:

    docker build -t 192.168.100.204:80/sd/sentinel:v2 .

    2、本地测试镜像

    docker run -d -p 81:8080 -e JAVA_OPTS='-Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dsentinel.dashboard.auth.username=sentinel -Dsentinel.dashboard.auth.password=sentinel -Dserver.servlet.session.timeout=7200' 192.168.100.204:80/sd/sentinel:v2
    

    浏览器访问:localhost:81

    3、上传至harbor(192.168.100.204:80)

    docker login 192.168.100.204:80
    docker push 192.168.100.204:80/sd/sentinel:v2
    

    4、创建StatefulSet和service

    新增sentinel.yaml和sentinel-service.yaml

    sentinel.yaml

    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: sentinel
    spec:
      serviceName: sentinel
      replicas: 1
      template:
        metadata:
          labels:
            app: sentinel
          annotations:
            pod.alpha.kubernetes.io/initialized: "true"
        spec:
          containers:
            - name: sentinel
              imagePullPolicy: IfNotPresent
              image: 192.168.100.204:80/sd/sentinel:v2
              ports:
                - containerPort: 8080
                  name: client
              env:
                - name: TZ
                  value: Asia/Shanghai
                - name: JAVA_OPTS
                  value: "-Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dsentinel.dashboard.auth.username=sentinel -Dsentinel.dashboard.auth.password=sentinel -Dserver.servlet.session.timeout=7200"
      selector:
        matchLabels:
          app: sentinel
    

    sentinel-service.yaml

    apiVersion: v1
    kind: Service
    metadata:
      name: sentinel-svc
      labels:
        app: sentinel
    spec:
      ports:
        - protocol: TCP
          name: http
          port: 8080
          targetPort: 8080
          nodePort: 31808
      type: NodePort
      selector:
        app: sentinel
    

    k8s部署:

    kubectl apply -f  sentinel.yaml
    kubectl apply -f  sentinel-service.yaml
    

    4、从外部通过serviceIP访问

    192.168.100.202:31808
    

    账号sentinel 密码sentinel

    java 中的对应配置去掉clientIp

    sentinel:
      ip: 192.168.100.202:31808
    spring:
      application:
        name: 66666666
      cloud:
        sentinel:
          transport:
            dashboard: ${sentinel.ip}
            port: 33000  #默认为8719 ,
            
            heartbeatIntervalMs: 1000
          eager: true
    

    相关文章

      网友评论

        本文标题:k8s:部署sentinel-dashboard

        本文链接:https://www.haomeiwen.com/subject/cakizltx.html