Win10安装Docker和k8s

一. 安装Chocolatey

1.1 什么是chocolatey

Chocolatey是一款专为Windows系统开发的、基于NuGet的包管理器工具,类似于Node.jsnpmMacOSbrewUbuntuapt-get,它简称为chocoChocolatey的设计目标是成为一个去中心化的框架,便于开发者按需快速安装应用程序和工具。

Chocolatey的官网: https://chocolatey.org/

1.2 安装

管理员身份运行powershell

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

在这里插入图片描述

1.3 查看

PS C:\WINDOWS\system32> choco
Chocolatey v0.10.15
Please run 'choco -?' or 'choco <command> -?' for help menu.

choco 其它命令如下:

choco -v 查看 choco 版本
choco list -li 查看本地安装的软件
choco search nodejs 查找安装包
choco install sublimetext3 下载
choco uninstall sublimetext3 卸载
choco upgrade sublimetext3 更新升级(update)
choco upgrade chocolatey 更新升级 chocolatey 自己

二. 安装LxRunOffline

2.1 使用Chocolatey安装

choco install lxrunoffline

在这里插入图片描述

2.2 LxRunOffline参数

如果执行命令报错,退出powershell再进入

PS C:\WINDOWS\system32> lxrunoffline version
LxRunOffline v3.5.0
PS C:\WINDOWS\system32> lxrunoffline
[ERROR] No action is specified.

Supported actions are:
    l, list            List all installed distributions.
    gd, get-default    Get the default distribution, which is used by bash.exe.
    sd, set-default    Set the default distribution, which is used by bash.exe.
    i, install         Install a new distribution.
    ui, uninstall      Uninstall a distribution.
    rg, register       Register an existing installation directory.
    ur, unregister     Unregister a distribution but not delete the installation directory.
    m, move            Move a distribution to a new directory.
    d, duplicate       Duplicate an existing distribution in a new directory.
    e, export          Export a distribution's filesystem to a .tar.gz file, which can be imported by the "install" command.
    r, run             Run a command in a distribution.
    di, get-dir        Get the installation directory of a distribution.
    gv, get-version    Get the filesystem version of a distribution.
    ge, get-env        Get the default environment variables of a distribution.
    se, set-env        Set the default environment variables of a distribution.
    ae, add-env        Add to the default environment variables of a distribution.
    re, remove-env     Remove from the default environment variables of a distribution.
    gu, get-uid        Get the UID of the default user of a distribution.
    su, set-uid        Set the UID of the default user of a distribution.
    gk, get-kernelcmd  Get the default kernel command line of a distribution.
    sk, set-kernelcmd  Set the default kernel command line of a distribution.
    gf, get-flags      Get some flags of a distribution. See https://docs.microsoft.com/en-us/previous-versions/windows/desktop/api/wslapi/ne-wslapi-wsl_distribution_flags for details.
    sf, set-flags      Set some flags of a distribution. See https://docs.microsoft.com/en-us/previous-versions/windows/desktop/api/wslapi/ne-wslapi-wsl_distribution_flags for details.
    s, shortcut        Create a shortcut to launch a distribution.
    ec, export-config  Export configuration of a distribution to an XML file.
    ic, import-config  Import configuration of a distribution from an XML file.
    sm, summary        Get general information of a distribution.
    version            Get version information about this LxRunOffline.exe.

三. LxRunOffline安装WSL2

3.1 前置设置

进入页面 更新 WSL 2 Linux 内核 下载Linux内核更新包,安装更新。

#用管理员模式启动PowerShell然后运行
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
这两个安装完成直接 重启 !!!!!!!!!重启!!!!!!

重启之后验证一下两个已经勾选
在这里插入图片描述
打开 PowerShell,右键以管理员身份运行,然后在安装新的 Linux 发行版时运行以下命令,将 WSL 2 设置为默认版本:

wsl --set-default-version 2

3.2 安装centos7子系统(选择一个安装)

3.2.1 微软商店安装Ubuntu20.04(推荐)

在这里插入图片描述
点击获取安装,然后点击启动

安装好之后设置用户wanfei,密码xxxxxx
在这里插入图片描述
修改root密码

wanfei@DESKTOP-073CCAL:/mnt/c/Users/Tophanter$ sudo passwd root
# 输入 wanfei 的密码
[sudo] password for wanfei:
# 输入密码 root
New password:
# 再一次输入密码 root
Retype new password:
passwd: password updated successfully

PowerShell界面LxRunOffline设置root为默认用户

lxrunoffline su -n Ubuntu-20.04 -v 0

root用户的 UID0

在这里插入图片描述

启动Ubuntu-20.04界面
在这里插入图片描述
使用LxRunOffline迁移到D盘

# 先关闭
PS C:\Users\Tophanter> wsl --shutdown
PS C:\Users\Tophanter> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-20.04    Stopped         2

# 查看已安装的Ubutun版本
PS C:\Users\Tophanter> lxrunoffline list
Ubuntu-20.04

# 迁移
PS C:\Users\Tophanter> LxRunOffline move -n Ubuntu-20.04 -d D:\WSL\Ubuntu

# 查看迁移后的WSL所在目录
PS C:\Users\Tophanter> lxrunoffline get-dir -n Ubuntu-20.04
D:\WSL\Ubuntu
3.2.2 使用LxRunOffline安装

下载 Centos7docker 镜像

可以参考 https://github.com/RoliSoft/WSL-Distribution-Switcher 来下载。

或者直接 下载

下载需要连接VPN

使用LxRunOffline安装CentOS7

# 安装
PS C:\WINDOWS\system32> lxrunoffline install -n centos7 -d D:\WSL\CentOS7 -f D:\gongJu\centos-7-docker.tar.xz

# 卸载
PS C:\WINDOWS\system32> lxrunoffline uninstall -n centos7

-n 用来指定名称,-d 后面是要安装到的目录,-f 是前面下载的镜像

虽然上面制定了wsl默认为2,但是这里还是1

PS C:\WINDOWS\system32> wsl -l -v
  NAME       STATE           VERSION
* centos7    Stopped         1

修改centos7 wsl版本

PS C:\WINDOWS\system32> wsl --set-version centos7 2
正在进行转换,这可能需要几分钟时间...
有关与 WSL 2 的主要区别的信息,请访问 https://aka.ms/wsl2
转换完成。
PS C:\WINDOWS\system32> wsl -l -v
  NAME       STATE           VERSION
* centos7    Stopped         2

这里也可以迁移centos7D盘

运行

lxrunoffline r -n centos7

[root@DESKTOP-H7HOHUB system32]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

LxRunOffline安装的Centos7,默认是以root用户登录

参考 https://blog.csdn.net/a772304419/article/details/114369974

参考 https://www.cnblogs.com/hongdada/p/13200158.html

3.2.3 通过商店安装(收费14块钱,用上面的比较好)

在这里插入图片描述
安装好之后设置用户wanfei,密码xxxxxx

修改root密码

[wanfei@DESKTOP-ILN245J ~]$ sudo passwd root
[sudo] password for wanfei:
# 输入 wanfei 的密码
Changing password for user root.
# 输入密码 root
New password:
BAD PASSWORD: The password is shorter than 8 characters
# 再一次输入密码 root
Retype new password:
passwd: all authentication tokens updated successfully.

LxRunOffline设置root为默认用户

lxrunoffline su -n Centos7 -v 0

root用户的 UID0

在这里插入图片描述
启动Centos7界面
在这里插入图片描述
更新系统(也可以不更新)

yum update -y

[root@DESKTOP-H7HOHUB-wsl ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

3.3 Windows Terminal

现在PowerShell切换到Centos7界面,命令无法复制粘贴,使用Windows Terminal

win10商店安装
在这里插入图片描述

3.4 配置xshell连接ssh(Unubtu)

3.4.1 先删ssh,再安装ssh
apt remove openssh-server -y
apt install openssh-server
3.4.2 修改配置文件
vim /etc/ssh/sshd_config

去除#,修改为

Port 2222
ListenAddress 0.0.0.0
PermitRootLogin yes # 开启允许远程登陆
PasswordAuthentication yes # 开启使用用户密码来作为连接验证
3.4.3 重启ssh
service ssh --full-restart
3.4.4 开机启动

参考 https://blog.csdn.net/shenbururen/article/details/106133150

配置延时2分钟
双击
在这里插入图片描述
触发器 -> 编辑
在这里插入图片描述
在这里插入图片描述

3.4.5 连接XShell测试

这个时候你自己电脑上的xshell是可以连接的了, 但是想要在其他的计算机上访问, 就需要系统开放端口了

这时需要到防火墙设置开放2222端口

防火墙 -> 高级设置 -> 入站规则 -> 新建规则
在这里插入图片描述
端口 -> 下一步

选择tcp 特定本地端口 2222
在这里插入图片描述
允许连接, 默认都选上, 下一步填个名字 完成

如果连不上,看看防火墙设置文件和打印机共享是否启用
在这里插入图片描述

使用发现win10 ipwsl2 ip不一样,使用win10 ip无法连接,只能使用127.0.0.1去连xshell,所以内网内的电脑也无法使用win10 ip连接,使用wsl2 ip可以连接,但是每次重启wsl2 ip会变,所以可以使用内网穿透去连接

3.4 配置xshell连接ssh(centos7)

执行命令

# 安装ssh
yum install -y openssl openssh-server

# 编辑配置
vi /etc/ssh/sshd_config
去除#,修改为

Port 2222
ListenAddress 0.0.0.0
PermitRootLogin yes # 开启允许远程登陆
PasswordAuthentication yes # 开启使用用户密码来作为连接验证

# 启动
# 执行一次
/usr/sbin/sshd-keygen -A
# 每次开机后要执行一次
nohup /usr/sbin/sshd -D >/dev/null 2>&1 &

四. 安装Docker

地址 https://www.docker.com/products/docker-desktop

安装好之后可能浏览器无法上网,微信可以上网,关闭代理
在这里插入图片描述

设置镜像加速 https://blog.csdn.net/czjnoe/article/details/114211013

添加

  "registry-mirrors": [
    "https://x83mabsk.mirror.aliyuncs.com",
    "https://registry.docker-cn.com",
    "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn",
    "https://reg-mirror.qiniu.com",
    "https://dockerhub.azk8s.cn",
    "https://mirror.ccs.tencentyun.com"
  ]

使用LxRunOffline迁移docker数据到D盘

PS C:\Users\16872> LxRunOffline.exe l
centos7
docker-desktop-data
docker-desktop

# 1. 运行命令前 点击退出 Docekr Desktop,然后三个就都 Stopped
PS C:\Users\16872> wsl -l -v
  NAME                   STATE           VERSION
* centos7                Stopped         2
  docker-desktop-data    Stopped         2
  docker-desktop         Stopped         2

# 2. 关闭所有发行版
wsl --shutdown

# 3. 新建docker-desktop-data文件夹,将docker-desktop-data导出到D:\WSL\docker-desktop-data\docker-desktop-data.tar(注意,原有的docker images不会一起导出)
wsl --export docker-desktop-data D:\WSL\docker-desktop-data\docker-desktop-data.tar

# 4. 注销docker-desktop-data
wsl --unregister docker-desktop-data

# 5. 重新导入docker-desktop-data到要存放的文件夹:D:\WSL\docker-desktop-data\
wsl --import docker-desktop-data D:\WSL\docker-desktop-data\ D:\WSL\docker-desktop-data\docker-desktop-data.tar --version 2

只需要迁移docker-desktop-data一个发行版就行,另外一个docker-desktop不用管,它占用空间很小。

完成以上操作后,原来的%LOCALAPPDATA%/Docker/wsl/data/ext4.vhdx就迁移到新目录了
在这里插入图片描述
每个文件夹下面都有ext4.vhdx这个文件
在这里插入图片描述

重启电脑校验迁移的功能是否正常

PS C:\Users\16872> wsl -l -v
  NAME                   STATE           VERSION
* centos7                Running         2
  docker-desktop-data    Running         2
  docker-desktop         Running         2

现在不用担心C盘爆满了。

可以查看安装路径

PS C:\Users\16872> LxRunOffline.exe list
docker-desktop-data
centos7
docker-desktop
PS C:\Users\16872> LxRunOffline.exe get-dir -n docker-desktop-data
\\?\D:\WSL\docker-desktop-data

卸载

#卸载命令,先要停止
wsl -t docker-desktop
wsl -t docker-desktop-data
wsl -t Centos7

# 卸载,会删除d盘里面迁移的目录
LxRunOffline.exe ui -n Centos7
LxRunOffline.exe ui -n docker-desktop-data
LxRunOffline.exe ui  -n docker-desktop

五. k8s

5.1 下载镜像

由于K8S需要一些镜像,如果一个个去下载,还是有点麻烦,我们可以借助一个阿里云现有的项目 AliyunContainerService/k8s-for-docker-desktop,一次把所有Image都下载好。

打开PowerShell,执行命令行

git clone https://github.com/AliyunContainerService/k8s-for-docker-desktop.git

然后参照里面的README.md指导

切换代码分支v1.19.7,使用 PowerShell

.\load_images.ps1

如果下载镜像,执行脚本报错,参考 https://blog.csdn.net/qq_44606649/article/details/104025066

5.2 安装

在这里插入图片描述

5.3 查看

[root@DESKTOP-H7HOHUB 16872]# kubectl get sc
NAME                 PROVISIONER          RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
hostpath (default)   docker.io/hostpath   Delete          Immediate           false                  35s
[root@DESKTOP-H7HOHUB 16872]# kubectl get nodes
NAME             STATUS   ROLES    AGE   VERSION
docker-desktop   Ready    master   66s   v1.19.7
[root@DESKTOP-H7HOHUB 16872]# kubectl get pods -n kube-system
NAME                                     READY   STATUS    RESTARTS   AGE
coredns-f9fd979d6-2c297                  1/1     Running   0          70s
coredns-f9fd979d6-krzlv                  1/1     Running   0          70s
etcd-docker-desktop                      1/1     Running   0          21s
kube-apiserver-docker-desktop            1/1     Running   0          8s
kube-controller-manager-docker-desktop   1/1     Running   0          7s
kube-proxy-jlxbg                         1/1     Running   0          70s
kube-scheduler-docker-desktop            1/1     Running   0          13s
storage-provisioner                      1/1     Running   0          67s
vpnkit-controller

默认安装了一个StorageClass hostpath,在电脑里面的地址是\\wsl$\docker-desktop-data\version-pack-data\community\k8s-pvs

参考 https://www.cnblogs.com/taylorshi/p/13698355.html

5.4 安装helm

下载地址 https://github.com/helm/helm/releases

[root@DESKTOP-H7HOHUB 16872]# mkdir -p ~/i/helm && cd ~/i/helm
[root@DESKTOP-H7HOHUB helm]# yum install wget -y
[root@DESKTOP-H7HOHUB helm]# wget https://get.helm.sh/helm-v3.5.4-linux-amd64.tar.gz

[root@DESKTOP-H7HOHUB helm]# ls
helm-v3.5.4-linux-amd64.tar.gz
[root@DESKTOP-H7HOHUB helm]# tar -xvf helm-v3.5.4-linux-amd64.tar.gz
linux-amd64/
linux-amd64/helm
linux-amd64/LICENSE
linux-amd64/README.md
[root@DESKTOP-H7HOHUB helm]# ls
helm-v3.5.4-linux-amd64.tar.gz  linux-amd64

[root@DESKTOP-H7HOHUB helm]# mv linux-amd64/helm /usr/local/bin
[root@DESKTOP-H7HOHUB helm]# helm version
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/config
version.BuildInfo{Version:"v3.5.4", GitCommit:"1b5edb69df3d3a08df77c9902dc17af864ff05d1", GitTreeState:"clean", GoVersion:"go1.15.11"}

配置helm仓库

helm repo add apphub https://apphub.aliyuncs.com
helm repo add stable https://charts.helm.sh/stable
helm repo update

5.5 helm安装nginx-ingress(有需要再安装,内网直接用 IP + NodePort)

该版本Docker Desktop最多为Docker Desktop 4.2.0,支持Kubernetes 1.21.5,下载地址https://docs.docker.com/desktop/windows/release-notes/#docker-desktop-420

搜索

[root@DESKTOP-H7HOHUB helm]# helm search repo apphub/nginx-ingress
NAME                            CHART VERSION   APP VERSION     DESCRIPTION
apphub/nginx-ingress            1.30.3          0.28.0          An nginx Ingress controller that uses ConfigMap...
apphub/nginx-ingress-controller 5.3.4           0.29.0          Chart for the nginx Ingress controller

安装

helm install nginx-ingress apphub/nginx-ingress --version 1.30.3 --namespace kube-system \
--set controller.image.repository=quay.io/kubernetes-ingress-controller/nginx-ingress-controller \
--set defaultBackend.image.repository=registry.cn-shanghai.aliyuncs.com/wanfei/defaultbackend-amd64

查看

[root@DESKTOP-H7HOHUB helm]# kubectl get pods -n kube-system | grep nginx
nginx-ingress-controller-df7695cbf-5vr49        1/1     Running   0          39s
nginx-ingress-default-backend-559457d54-jx8l9   1/1     Running   0          39s

5.6 将集群导入线上的Rancher

添加集群
在这里插入图片描述
导入
在这里插入图片描述
台式机本地k8s集群加入
在这里插入图片描述
在这里插入图片描述
复制到台式机本地k8s集群内执行命令
等待一会儿
在这里插入图片描述
创建了cattle-system命令空间

5.7 安装harbor

apphub/harbor版本4.0.0,密码一直错误,不要使用,下面通过从git下载helm chart

5.7.1 下载
git clone https://github.com/goharbor/harbor-helm
5.7.2 配置文件
cat <<EOF> my-values.yaml
expose:
  type: nodePort
  tls:
    enabled: false

externalURL: http://127.0.0.1:30002
harborAdminPassword: "Harbor12345"

persistence:
  persistentVolumeClaim:
    registry:
      storageClass: "hostpath"
    chartmuseum:
      storageClass: "hostpath"
    jobservice:
      storageClass: "hostpath"
    database:
      storageClass: "hostpath"
    redis:
      storageClass: "hostpath"
    trivy:
      storageClass: "hostpath"
EOF
  • hostpath:是默认生成的StorageClsss
  • expose.tls.enabled=false:必须要设置,否则访问不了
5.7.3 安装
kubectl create ns kube-ops

helm install harbor -f my-values.yaml . --namespace kube-ops

查询

[root@DESKTOP-TEOEPLI harbor-helm]# kubectl get pods -n kube-ops
NAME                                           READY   STATUS    RESTARTS   AGE
harbor-harbor-chartmuseum-57956b498b-5qfq9     1/1     Running   0          3m35s
harbor-harbor-core-b568dfcc8-tvtff             1/1     Running   0          3m35s
harbor-harbor-database-0                       1/1     Running   0          3m35s
harbor-harbor-jobservice-79c89bcbb7-gc6cs      1/1     Running   0          3m35s
harbor-harbor-nginx-577c78c7f5-f8bsv           1/1     Running   0          3m35s
harbor-harbor-notary-server-68c866f597-qjpmv   1/1     Running   0          3m35s
harbor-harbor-notary-signer-6cbf4b5999-fptxm   1/1     Running   0          3m35s
harbor-harbor-portal-78b9d96fb9-6kkg8          1/1     Running   0          3m35s
harbor-harbor-redis-0                          1/1     Running   0          3m35s
harbor-harbor-registry-68cb47cb97-bpcvh        2/2     Running   0          3m35s
harbor-harbor-trivy-0                          1/1     Running   0          3m35s
5.7.4 访问

访问 http://127.0.0.1:30002/

账号密码:admin/Harbor12345

在这里插入图片描述

5.7.5 docker login
[root@DESKTOP-TEOEPLI harbor-helm]# docker login -u admin -p Harbor12345 127.0.0.1:30002
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Login Succeeded

5.8 安装jenkins

5.8.1 添加ali
helm repo add ali https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
5.8.2 搜索
[root@DESKTOP-TEOEPLI helm]# helm search repo ali/jenkins
NAME            CHART VERSION   APP VERSION     DESCRIPTION
ali/jenkins     0.13.5          2.73            Open source continuous integration server. It s...
5.8.3 下载
[root@DESKTOP-H7HOHUB helm]# helm pull ali/jenkins
[root@DESKTOP-H7HOHUB helm]# tar -xvf jenkins-0.13.5.tgz
5.8.4 新建配置文件(NodePort)
[root@DESKTOP-H7HOHUB helm]# cd jenkins

cat <<EOF> my-values.yaml
Master:
  AdminPassword: www19930327
  ServiceType: NodePort
  NodePort: 30005

Persistence:
  StorageClass: "hostpath"
  Size: "5Gi"

rbac:
  install: true
EOF
5.8.5 修改下模板文件
[root@master jenkins]# ls
Chart.yaml  my-values.yaml  OWNERS  README.md  templates  values.yaml
[root@master jenkins]# cd templates/
[root@master templates]# ls
config.yaml   home-pvc.yaml           jenkins-master-deployment.yaml  jenkins-master-networkpolicy.yaml  jenkins-test.yaml  NOTES.txt  secret.yaml           test-config.yaml
_helpers.tpl  jenkins-agent-svc.yaml  jenkins-master-ingress.yaml     jenkins-master-svc.yaml            jobs.yaml          rbac.yaml  service-account.yaml
[root@master templates]# vi jenkins-master-deployment.yaml 

在这里插入图片描述
第一行修改为apps/v1

5.8.6 安装
helm install jenkins -f my-values.yaml . --namespace kube-ops

查看

[root@DESKTOP-TEOEPLI jenkins]# kubectl get pods -n kube-ops | grep jenkins
jenkins-547df9c789-crq4m                       1/1     Running   0          16m
5.8.7 访问

访问 http://127.0.0.1:30005/

账号:admin 密码上面设置的是www19930327

点击 X 跳过插件安装

5.8.8 安装插件

登录后更新插件

安装中文插件Localization: Chinese (Simplified),点第二个,安装后重启
在这里插入图片描述
安装 多选参数 插件Extended Choice Parameter,后面可能会用到

5.8.9 配置凭据

配置 上面安装的 Harbor 凭据
在这里插入图片描述
点击系统
在这里插入图片描述
添加凭据
在这里插入图片描述
在这里插入图片描述

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值