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: mysqlnamespace: wordpresslabels:app: mysql
spec:replicas: 1selector:matchLabels:app: mysqlstrategy: {}template:metadata:creationTimestamp: nulllabels:app: mysqlspec:containers:- image: mysql:5.7name: mysqlimagePullPolicy: IfNotPresentports:- containerPort: 3306name: dbportenv: #环境编排,进入数据库中创建Wordpress数据库和WordPress用户- name: MYSQL_ROOT_PASSWORDvalue: root- name: MYSQL_DATABASEvalue: wordpress- name: MYSQL_USERvalue: wordpress- name: MYSQL_PASSWORDvalue: wordpressvolumeMounts:- name: dbmountPath: /var/lib/mysql #mysql数据存放的容器目录resources: {}volumes:- name: dbhostPath:path: /var/lib/mysql # 容器目录中的数据映射到本地目录中
status: {}
---
apiVersion: v1
kind: Service
metadata:name: mysqlnamespace: wordpress
spec:selector:app: mysqlports:- name: mysqlportprotocol: TCPport: 3306targetPort: dbport
2.2 wordpress.yaml
apiVersion: apps/v1
kind: Deployment
metadata:name: wordpressnamespace: wordpresslabels:app: wordpress
spec:replicas: 1selector:matchLabels:app: wordpressstrategy: {}template:metadata:creationTimestamp: nulllabels:app: wordpressspec:containers:- name: wordpressimage: wordpressimagePullPolicy: IfNotPresentports:- containerPort: 80name: wdportenv:- name: WORDPRESS_DB_HOSTvalue: mysql:3306 #连接数据库,这里的ip地址查看mysql启动时的ip- name: WORDPRESS_DB_USERvalue: wordpress- name: WORDPRESS_DB_PASSWORDvalue: wordpress
status: {}
---
apiVersion: v1
kind: Service
metadata:name: wordpressnamespace: wordpress
spec:type: NodePortselector:app: wordpressports:- name: wordpressportprotocol: TCPport: 80targetPort: wdport
3.k8s部署ubuntu并挂载宿主机文件夹
apiVersion: v1
kind: Pod
metadata:name: ubuntu
spec:containers:- name: ubuntuimage: ubuntu:latestcommand: ["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 #模式