目录

1、构建镜像(DockerFile)

2、本地测试镜像(docker-compose)

3、创建StatefulSet和service

4、通过serviceIP访问 

 

1、构建镜像(DockerFile)

FROM java8-alpine
MAINTAINER lusain
VOLUME /tmp
ADD ./sentinel-dashboard/target/*.jar sentinel-dashboard.jar
EXPOSE 8080
CMD java ${JAVA_OPTS} -jar sentinel-dashboard.jar

构建:


docker build -t  hub.com/sentinel-dashboard:v2 .

2、本地测试镜像(docker-compose)

version: "2"
services:
  namesrv:
    image: hub.com/sentinel-dashboard:v2
    container_name: sentinel-dashboard
    ports:
      - 30080:8080
    environment:
      - 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

启动容器:

docker-compose up -d 

浏览器访问:localhost:30080 

3、创建StatefulSet和service

新增sentinel.yaml

# 外部访问服务
apiVersion: v1
kind: Service
metadata:
  name: sentinel
  labels:
    app: sentinel
spec:
  ports:
    - protocol: TCP
      name: http
      port: 8858
      targetPort: 8080
  type: ClusterIP
  selector:
    app: sentinel
---
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: hub.com//sentinel-dashboard:v2
          resources:
            limits:
              memory: "1Gi"
              cpu: "1"
          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

 k8s部署:

kubectl apply -f  sentinel.yaml

4、通过serviceIP访问 

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐