Installing minikube-dashboard + Auto-start and External Network Access
1. Installing minikube-dashboard
Refer to the official documentation: https://minikube.sigs.k8s.io/docs/start/ Execute the command
minikube dashboard
2. Installing the Minikube Background Service
If you want minikube to start only once under systemctl management and exit automatically after successful startup, you can modify the service file for systemctl to prevent automatic restart of minikube. This can be achieved by setting Restart=no, and ensuring the service is started manually only when needed.
Below is a basic systemctl service file example suitable for this scenario:
#minikube自启动脚本
#/etc/systemd/system/minikube.service
[Unit]
Description=Minikube Kubernetes
After=docker.service
Requires=docker.service
[Service]
Type=oneshot
User=root
RemainAfterExit=yes
Environment="HOME=/root"
Environment="MINIKUBE_HOME=/root/.minikube"
ExecStart=/usr/local/bin/minikube start --force
[Install]
WantedBy=multi-user.target
Explanation
-
Type=oneshot: This indicates that the service is one-shot, meaning it is considered complete after executing once. This is useful for executing scripts or commands that do not need to keep running after completion.
-
RemainAfterExit=yes: Even if the main process of the service has exited, the service is still considered active. This applies when
minikubestartup is complete, as it does not require a persistent background process to run. -
Restart=no: This means that if the service exits, regardless of success or failure,
systemdwill not attempt to restart the service.
Usage Steps
-
Create the service file: Save the above content to
/etc/systemd/system/minikube.service. -
Reload
systemdconfiguration: Updatesystemdto recognize your new service or changes to the service file.sudo systemctl daemon-reload -
Start the service: Use
systemctlto start theminikubeservice.sudo systemctl start minikube.service -
Check the status: Verify the service status to ensure there are no errors.
sudo systemctl status minikube.service -
Enable the service: If you want Minikube to run automatically at system startup (execute once, then exit), you can enable the service.
sudo systemctl enable minikube.service
With this configuration, Minikube will run once at system startup, initialize, and then exit, but will not restart automatically.
3. Installing the minikube-dashboard Background Service
- The steps are the same as above and will not be repeated; here is a simplified operation guide
- Edit the file
/etc/systemd/system/minikube-dashboard.service
#Minikube自启动并自动映射 dashboard 端口
#/etc/systemd/system/minikube-dashboard.service
[Unit]
Description=Auto-start Kubernetes Dashboard with port-forwarding
After=minikube.service
Requires=minikube.service
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=root
Environment="HOME=/root"
Environment="MINIKUBE_HOME=/root/.minikube"
ExecStartPre=kubectl wait --for=condition=ready pod --selector=k8s-app=kubernetes-dashboard -n kubernetes-dashboard --timeout=120s
ExecStart=/bin/bash -c 'kubectl port-forward --address 0.0.0.0 service/kubernetes-dashboard 8080:80 -n kubernetes-dashboard'
RemainAfterExit=no
[Install]
WantedBy=multi-user.target
*常规服务操作
#重载服务配置
sudo systemctl daemon-reload
#配置自启动
sudo systemctl enable minikube-dashboard.service
#手工启动服务
sudo systemctl start minikube-dashboard.service
#查看服务状态
sudo systemctl status minikube-dashboard.service