机器环境
本实践将在 Ubuntu 22.04.3LTS 系统上进行安装测试
docker 版本,原则上docker版本无影响
docker version
Client: Docker Engine - Community
Version: 24.0.6
API version: 1.43
Go version: go1.20.7
Git commit: ed223bc
Built: Mon Sep 4 12:31:44 2023
OS/Arch: linux/amd64
Context: default
安装portainer操作脚本
参考资料 [Linux install]
# DockerStandalone
# 默认方式
docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always\
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data portainer/portainer-ce:2.14.2
# 安装到特定网络 , net_default已经提前创建完成
docker run -d -p 8000:8000 -p 9000:9000 --name portainer --restart=always\
-v /var/run/docker.sock:/var/run/docker.sock --network net_default\
-v portainer_data:/data portainer/portainer-ce:2.14.2
安装代理到已经存在的portainer
# Add an environment to an existing installation
## Docker Standalone
docker run -d -p 10.10.4.128:9001:9001 --name portainer_agent --restart=always\
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/lib/docker/volumes:/var/lib/docker/volumes portainer/agent:2.14.2
# Add k8s
curl -L https://downloads.portainer.io/ee2-14/portainer-agent-k8s-nodeport.yaml -o portainer-agent-k8s.yaml;
kubectl apply -f portainer-agent-k8s.yaml
访问
访问地址:docker
http://10.10.4.128:9000k8s
http://10.10.4.128:30778
配置到ingress
portainer_ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: portainer
namespace: portainer
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: "0"
spec:
rules:
- host: portainer.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: portainer
port:
number: 9000
ingressClassName: nginx
ingress 访问地址
http://portainer.example.com
重置密码
某一天忘记密码或其他异常导致密码被动忘记掉
找到portainer的数据目录
portainer_data:/data
docker安装用 docker inspect container_name or container_id 查看 "Mounts": [ ..... { "Type": "bind", "Source": "/data", "Destination": "/data", "Mode": "", "RW": true, "Propagation": "rprivate" } ],
k8s安装用 kubectl describe pods portainer-5d4754696-ngdn6 -n portainer 查看
Volumes:
data:
Type: HostPath (bare host directory volume)
Path: /data
HostPathType: Directory
```
> 上面找到的真实地址是 `/data`
- 关闭portainer
- 运行重置命令
docker run --rm -v /data:/data portainer/helper-reset-password
{"level":"info","filename":"portainer.db","time":"2024-03-28T01:10:00Z","message":"loading PortainerDB"}
2024/04/01 01:10:00 Password successfully updated for user: admin
2024/04/01 01:10:00 Use the following password to login: ~3%2gWf,hb[n5$4F:UI0w78x!QE{l6Zt
输出日志中包含有admin
的密码~3%2gWf,hb[n5$4F:UI0w78x!QE{l6Zt
- 启动portainer
- 输入上述密码 ,登录portainer后台,修改密码。