前置环境
配置依赖
配置域名(可选)
address=/sentinel.basic.tanqidi.com/172.31.0.100
address=/sentinel.dev.tanqidi.com/172.31.0.100
1. 镜像构建
https://github.com/alibaba/Sentinel/releases
https://sentinelguard.io/zh-cn/docs/introduction.html
docker build -t tanqidi/sentinel-service .
我帮你下载好了:sentinel-dashboard-1.8.8.jar
# 使用 OpenJDK 11 作为基础镜像
FROM openjdk:11-jre-slim
# 设置工作目录
WORKDIR /app
# 复制 Sentinel 服务的 JAR 包到容器中
COPY sentinel-dashboard-1.8.8.jar /app/sentinel-service.jar
# 暴露服务使用的端口(根据你的应用设置调整)
EXPOSE 8080
# 设置环境变量(根据需要调整)
ENV JAVA_OPTS="-Xms512m -Xmx512m"
# 启动 Sentinel 服务
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /app/sentinel-service.jar"]
2. docker 部署
默认账号密码都是 sentinel
# 8080太常见了容易冲突,我使用8333来试验
docker run -d --name sentinel-service -p 8333:8080 \
-e JAVA_OPTS="-Dsentinel.dashboard.auth.username=admin -Dsentinel.dashboard.auth.password=123456" \
tanqidi/sentinel-service
3. kubernetes 部署
3.1 configmap
如果不配置的话,默认的账号密码都是sentinel
https://sentinelguard.io/zh-cn/docs/introduction.html
kind: ConfigMap
apiVersion: v1
metadata:
name: sentinel-conf
namespace: basic
annotations:
kubesphere.io/creator: admin
data:
JAVA_OPTS: |-
-Dsentinel.dashboard.auth.username=admin
-Dsentinel.dashboard.auth.password=123456
3.2 deployment
kind: Deployment
apiVersion: apps/v1
metadata:
name: sentinel-service
namespace: basic
labels:
app: sentinel-service
annotations:
deployment.kubernetes.io/revision: '1'
kubesphere.io/creator: admin
spec:
replicas: 1
selector:
matchLabels:
app: sentinel-service
template:
metadata:
creationTimestamp: null
labels:
app: sentinel-service
annotations:
kubesphere.io/creator: admin
kubesphere.io/imagepullsecrets: '{}'
spec:
volumes:
- name: host-time
hostPath:
path: /etc/localtime
type: ''
containers:
- name: container-3ikwrh
image: registry.cn-hangzhou.aliyuncs.com/tanqidi/sentinel-service
ports:
- name: tcp-8080
containerPort: 8080
protocol: TCP
env:
- name: JAVA_OPTS
valueFrom:
configMapKeyRef:
name: sentinel-conf
key: JAVA_OPTS
resources: {}
volumeMounts:
- name: host-time
readOnly: true
mountPath: /etc/localtime
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: Always
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
serviceAccountName: default
serviceAccount: default
securityContext: {}
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
3.3 service
使用NodePort来试验访问
kind: Service
apiVersion: v1
metadata:
name: sentinel-service
namespace: basic
labels:
app: sentinel-service
annotations:
kubesphere.io/creator: admin
spec:
ports:
- name: http-8080
protocol: TCP
port: 8080
targetPort: 8080
nodePort: 32263
selector:
app: sentinel-service
type: NodePort
sessionAffinity: None
externalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
internalTrafficPolicy: Cluster
3.4 coredns
rewrite name sentinel.basic.tanqidi.com sentinel.basic.svc.cluster.local
4. 镜像制品
tanqidi/sentinel-service
registry.cn-hangzhou.aliyuncs.com/tanqidi/sentinel-service
5. 写在最后
通过JAVA_OPTS变量来传递运行参数能很好的控制它运行了,具体的话各位可以看官网怎么配置就好了。