dockerdsktop修改安装路径/k8s部署wordpress和ubuntu
1.安装DockerDesktop
1.1下载DockerDesktop
1.2 找到Docker Desktop Installer.exe 重命名 DockerDesktopInstaller.exe
命令安装
#使用命令参数
使用了如下参数
./dockerdesk.exe install
–accept-license --backend=wsl-2
–installation-dir=‘docker-desktop安装位置’
–wsl-default-data-root=‘docker-desktop-data安装位置’
./dockerdesk.exe install --accept-license --backend=wsl-2 --installation-dir='D:\DockerDesktop' --wsl-default-data-root='D:\DockerDesktopWSL'
2.k8s部署wordpress
2.1 wordpress-db.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
namespace: wordpress
labels:
app: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: mysql
spec:
containers:
- image: mysql:5.7
name: mysql
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3306
name: dbport
env: #环境编排,进入数据库中创建Wordpress数据库和WordPress用户
- name: MYSQL_ROOT_PASSWORD
value: root
- name: MYSQL_DATABASE
value: wordpress
- name: MYSQL_USER
value: wordpress
- name: MYSQL_PASSWORD
value: wordpress
volumeMounts:
- name: db
mountPath: /var/lib/mysql #mysql数据存放的容器目录
resources: {}
volumes:
- name: db
hostPath:
path: /var/lib/mysql # 容器目录中的数据映射到本地目录中
status: {}
---
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: wordpress
spec:
selector:
app: mysql
ports:
- name: mysqlport
protocol: TCP
port: 3306
targetPort: dbport
2.2 wordpress.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
namespace: wordpress
labels:
app: wordpress
spec:
replicas: 1
selector:
matchLabels:
app: wordpress
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: wordpress
spec:
containers:
- name: wordpress
image: wordpress
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
name: wdport
env:
- name: WORDPRESS_DB_HOST
value: mysql:3306 #连接数据库,这里的ip地址查看mysql启动时的ip
- name: WORDPRESS_DB_USER
value: wordpress
- name: WORDPRESS_DB_PASSWORD
value: wordpress
status: {}
---
apiVersion: v1
kind: Service
metadata:
name: wordpress
namespace: wordpress
spec:
type: NodePort
selector:
app: wordpress
ports:
- name: wordpressport
protocol: TCP
port: 80
targetPort: wdport
3.k8s部署ubuntu并挂载宿主机文件夹
apiVersion: v1
kind: Pod
metadata:
name: ubuntu
spec:
containers:
- name: ubuntu
image: ubuntu:latest
command: ["sleep"]
args: ["3600"]
volumeMounts:
- name: myvolume # 卷名
mountPath: /mnt # 卷路径
resources: {}
volumes:
- name: myvolume
hostPath:
path: /var/lib/data # 主机路径node节点的机器上
type: DirectoryOrCreate #模式
宿主机文件夹位置
\\wsl.localhost\docker-desktop\mnt\docker-desktop-disk\data
pod挂载宿主机配置
volumes:
- name: myvolume
hostPath:
path: /var/lib/data # 主机路径node节点的机器上
type: DirectoryOrCreate #模式