- 1. 通过Jar包,生成镜像,推送到镜像仓库
- 2. 编写 sentinel.yaml 及 sentinel-statefulset.yaml
- 2.1 编写sentinel.yaml
- 2.2 编写 sentinel-statefulset.yaml
- 2.3 启动测试
- 2.4 浏览器访问Sentinel-dashboard
- http://your-ip:31808/(**31808 为 sentinel.yaml 中配置的nodePort**) 输入用户名密码 sentinel,点击登录">http://your-ip:31808/(**31808 为 sentinel.yaml 中配置的nodePort**) 输入用户名密码 sentinel,点击登录
- 2.5 Sentinel-Dashboard 安装成功
1. 通过Jar包,生成镜像,推送到镜像仓库
1.1 通过 Sentinel 官方,下载Jar包
https://github.com/alibaba/Sentinel/releases
1.2 编写Dockerfile
FROM java:8
VOLUME /tmp
ADD sentinel-dashboard-1.7.2.jar sentinel-dashboard.jar
CMD java ${JAVA_OPTS} -jar sentinel-dashboard.jar
EXPOSE 8080
1.3 根据Dockerfile 生成镜像
[root@k8s-master ~]# docker build -t easycamp/sentinel-dashboard .
Sending build context to Docker daemon 193MB
Step 1/5 : FROM java:8
---> d23bdf5b1b1b
Step 2/5 : VOLUME /tmp
---> Running in ee8e93f9996f
Removing intermediate container ee8e93f9996f
---> 6677c980f695
Step 3/5 : ADD sentinel-dashboard-1.7.2.jar sentinel-dashboard.jar
---> 36fc452961eb
Step 4/5 : CMD java ${JAVA_OPTS} -jar sentinel-dashboard.jar
---> Running in c2739ade26e0
Removing intermediate container c2739ade26e0
---> 1f936874a139
Step 5/5 : EXPOSE 8080
---> Running in c633881219e8
Removing intermediate container c633881219e8
---> dc3e65fd52eb
Successfully built dc3e65fd52eb
Successfully tagged easycamp/sentinel-dashboard:latest
1.4 将本地镜像推送到阿里云镜像仓库中
sudo docker login --username=your username registry.cn-hangzhou.aliyuncs.com
sudo docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/xxx:[镜像版本号]
sudo docker push registry.cn-hangzhou.aliyuncs.com/xxx:[镜像版本号]
1.5 查看阿里云镜像仓库是否包含这个镜像
2. 编写 sentinel.yaml 及 sentinel-statefulset.yaml
2.1 编写sentinel.yaml
因为采用的是官方jar包,且在Dockerfile中没有额外指定其他的端口,所以,此yaml文件中的port均为8080,如在Dockerfile中额外指定了端口,则需将port相关的修改为对应的端口
---
apiVersion: v1
kind: Service
metadata:
name: sentinel
labels:
app: sentinel
annotations:
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
spec:
ports:
- port: 8080
name: server
targetPort: 8080
clusterIP: None
selector:
app: sentinel
---
# 外部访问服务
apiVersion: v1
kind: Service
metadata:
name: sentinel-svc
labels:
app: sentinel
spec:
ports:
- name: http
protocol: "TCP"
port: 8080
targetPort: 8080
nodePort: 31808
type: NodePort
selector:
app: sentinel
2.2 编写 sentinel-statefulset.yaml
注意 containerPort 以及 image,修改成自己的 image地址
---
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: cike/sentinel-dashboard-docker:latest
resources:
requests:
memory: "512Mi"
cpu: "200m"
ports:
- containerPort: 8080
name: client
env:
- name: TZ
value: Asia/Shanghai
- name: JAVA_OPTS
value: "-Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -Djava.security.egd=file:/dev/./urandom -Dcsp.sentinel.api.port=8719"
selector:
matchLabels:
app: sentinel
2.3 启动测试
[root@k8s-master ~]# kubectl apply -f sentinel.yaml
service/sentinel created
service/sentinel-svc created
[root@k8s-master ~]# kubectl apply -f sentinel-statefulset.yaml
statefulset.apps/sentinel created
运行发现,可能会报如下的错误,会说,需要登录才能从私有仓库中拉取镜像
Failed to pull image "registry.cn-hangzhou.aliyuncs.com/xxx:1.7.2":
rpc error: code = Unknown desc = Error response from daemon:
pull access denied for registry.cn-hangzhou.aliyuncs.com/xxx,
repository does not exist or may require 'docker login'
根据如上的问题,解决方法如下:
1. 创建一个密钥
kubectl create secret docker-registry registry-key \
--docker-server=registry.cn-hangzhou.aliyuncs.com \
--docker-username=your user name \
--docker-password=<your-password> \
--docker-email=xxx@qq.com
2. 修改 sentinel-statefulset.yaml,添加拉取时所使用的密钥
添加 imagePullSecrets
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:
imagePullSecrets:
- name: registry-key
添加密钥之后,delete之后,重新启动
[root@k8s-master ~]# kubectl delete -f sentinel.yaml
service "sentinel" deleted
service "sentinel-svc" deleted
[root@k8s-master ~]# kubectl delete -f sentinel-statefulset.yaml
statefulset.apps "sentinel" deleted
[root@k8s-master ~]# kubectl apply -f sentinel.yaml
service/sentinel created
service/sentinel-svc created
[root@k8s-master ~]# kubectl apply -f sentinel-statefulset.yaml
statefulset.apps/sentinel created
发现,已经成功启动
[root@k8s-master ~]# kubectl get pods;
NAME READY STATUS RESTARTS AGE
sentinel-0 1/1 Running 0 9m37s