当前位置: 首页> 教育> 大学 > 月亮湾设计有限公司网站_html网页制作模板代码免费_推广搜索怎么选关键词_站内优化seo

月亮湾设计有限公司网站_html网页制作模板代码免费_推广搜索怎么选关键词_站内优化seo

时间:2025/7/9 17:06:13来源:https://blog.csdn.net/qq_32789063/article/details/147074832 浏览次数:1次
月亮湾设计有限公司网站_html网页制作模板代码免费_推广搜索怎么选关键词_站内优化seo

基于win 10 打造K8S应用开发环境(wsl & kind)

一、wsl子系统安装

1.1 确认windows系统版本

cmd/powershell
在这里插入图片描述
或者win + r 运行winver
在这里插入图片描述

操作系统要>= 19044
在这里插入图片描述

1.2 开启wsl功能

控制面板 -> 程序 -> 启用或关闭Windows功能
开启适用于Linux的windows子系统 & 虚拟机平台
在这里插入图片描述
确认完成后,电脑会重启。

1.3 wsl配置

wsl
适用于 Linux 的 Windows 子系统没有已安装的分发版。
可以通过访问 Microsoft Store 来安装分发版:
https://aka.ms/wslstore#更改新分发的默认安装版本为2
wsl --set-default-version 2
#WSL 2 内核更新
wsl --update#获得有效分发列表
wsl --list --online#安装Ubuntu
wsl --install -d Ubuntu

1.4 wsl命令解释

获取帮助文档

wsl --help
版权所有(c) Microsoft Corporation。保留所有权利。用法: wsl.exe [Argument] [Options...] [CommandLine]运行 Linux 二进制文件的参数:如果未提供命令行,wsl.exe 将启动默认 shell。--exec, -e <CommandLine>在不使用默认 Linux Shell 的情况下执行指定的命令。--按原样传递其余命令行。选项:--cd <Directory>将指定目录设置为当前工作目录。如果使用了 ~,则将使用 Linux 用户的主页路径。如果路径以 / 字符开头,将被解释为绝对 Linux 路径。否则,该值一定是绝对 Windows 路径。--distribution, -d <Distro>运行指定分发。--user, -u <UserName>以指定用户身份运行。管理适用于 Linux 的 Windows 子系统的参数:--help显示用法信息。--install [选项]安装额外的适用于 Linux 的 Windows 子系统分发。要获得有效分发列表,请使用“wsl --list --online”。选项:--distribution, -d [参数]按名称下载并安装分发。参数:有效分发名称(不区分大小写)。示例:wsl --install -d Ubuntuwsl --install --distribution Debian--set-default-version <Version>更改新分发的默认安装版本。--shutdown立即终止所有运行的分发及 WSL 2轻型实用工具虚拟机。--status显示适用于 Linux 的 Windows 子系统的状态。--update [Options]如果未指定任何选项,则将 WSL 2 内核更新为最新版本。选项:--rollback恢复为 WSL 2 内核的先前版本。--inbox仅更新收件箱 WSL 2 内核。不要从 Microsoft Store 下载 WSL。--web-download从 Internet 而不是 Microsoft Store 下载最新版本的 WSL。用于管理适用于 Linux 的 Windows 子系统中的分发的参数:--export <Distro> <FileName>将分发导出到 tar 文件。对于标准输出,文件名可以是 ---import <Distro> <InstallLocation> <FileName> [Options]将指定的 tar 文件作为新分发导入。对于标准输入,文件名可以是 -。选项:--version <Version>指定要用于新分发的版本。--list, -l [Options]列出分发。选项:--all列出所有分发,包括当前正在安装或卸载的分发。--running仅列出当前正在运行的分发。--quiet, -q仅显示分发名称。--verbose, -v显示所有分发的详细信息。--online, -o显示使用“wsl --install”进行安装的可用分发列表。--set-default, -s <分发>将分发设置为默认值。--set-version <分发> <版本>更改指定分发的版本。--terminate, -t <分发>终止指定的分发。--unregister <分发>注销分发并删除根文件系统。

更改新分发的默认安装版本为2

wsl --set-default-version 2

WSL 2 内核更新

wsl --update

获得有效分发列表

wsl --list --online

安装额外的适用于 Linux 的 Windows 子系统分发Ubuntu

wsl --install -d Ubuntu

运行指定分发。

wsl -d Ubuntu

运行默认的分发

wsl

列出分发并显示版本

wsl -l -v

将Ubuntu分发设置为默认值

wsl --set-default Ubuntu

终止指定的分发。将Runing变成Stopped

wsl --terminate Ubuntu

注销分发并删除根文件系统。

wsl --unregister Ubuntu

显示适用于 Linux 的 Windows 子系统的状态。

wsl --status
默认分发: Ubuntu
默认版本: 2

以指定用户身份运行

wsl --user root
root@DESKTOP-KCURLDV:/mnt/c/Users/Administrator#

二、安装Docker Desktop

2.1 下载docker Desktop

https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe?utm_source=docker&utm_medium=webreferral&utm_campaign=dd-smartbutton&utm_location=module&_gl=1*5ht9ce*_gcl_au*MjQwMDkyNDQ0LjE3NDQxMTQzMzg.*_ga*MTM1ODM2MjU5NS4xNzQ0MTE0MzEx*_ga_XJWPQMJYHQ*MTc0NDExNDMxMS4xLjEuMTc0NDExNjM4OC41MC4wLjA.

2.2 安装以及设置
一步步安装就行。

docker配置如下图所示
在这里插入图片描述
在这里插入图片描述

三、Golang安装

功能:可以安装多个golang版本,可以切换golang版本

# bash < <(curl -s -S -L root@DESKTOP-KCURLDV:~# source /root/.gvm/scripts/gvm
-bash: /root/.gvm/scripts/gvm: No such file or directory
root@DESKTOP-KCURLDV:~# bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
Cloning from https://github.com/moovweb/gvm.git to /root/.gvm
No existing Go versions detected
ERROR: Missing requirements.
Installed GVM v1.0.22Please restart your terminal session or to get started right away run`source /root/.gvm/scripts/gvm`# source /root/.gvm/scripts/gvm
ERROR: Missing requirements.

需要退出Ubuntu终端,再登入即可有gvm命令


# gvm versionCould not find bisonlinux: apt-get install bisonCould not find gcclinux: apt-get install gccCould not find makelinux: apt-get install makeERROR: Missing requirements.# apt-get update
# apt-get install bison gcc make
# gvm version
Go Version Manager v1.0.22 installed at /root/.gvm# gvm
Usage: gvm [command]Description:GVM is the Go Version ManagerCommands:version    - print the gvm version numberget        - gets the latest code (for debugging)use        - select a go version to use (--default to set permanently)diff       - view changes to Go roothelp       - display this usage textimplode    - completely remove gvminstall    - install go versionsuninstall  - uninstall go versionscross      - install go cross compilerslinkthis   - link this directory into GOPATHlist       - list installed go versionslistall    - list available versionsalias      - manage go version aliasespkgset     - manage go packages setspkgenv     - edit the environment for a package setapplymod   - apply the go version in go.mod
# gvm listallgvm gos (available)go1go1.0.1go1.0.2go1.0.3go1.1....# gvm install go1.19 -B
Installing go1.19 from binary source
# gvm install go1.20.3 -B
Installing go1.20.3 from binary source# gvm use go1.19
Now using version go1.19# gvm list
gvm gos (installed)=> go1.19go1.20.3
# gvm use go1.20.3
# gvm listgvm gos (installed)go1.19
=> go1.20.3

四、kubectl安装

Kind 只负责创建集群(会配置好 kubeconfig),后续操作集群的话需要手动安装 kubectl.

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin

五、Golang安装下载

5.1 下载安装地址(傻瓜式)

https://www.jetbrains.com/go/download/#section=windows
在这里插入图片描述

5.2 创建Project

在这里插入图片描述
在这里插入图片描述

location:     \\wsl$\Ubuntu\root\aiops
GOROOT:       \\wsl$\Ubuntu\root\.gvm\gos\go1.19

在这里插入图片描述

5.3 无法访问\wsl$\Ubuntu\root\解决

在这里插入图片描述
原因分析:
因此,我查找了WSL官方文档(WSL 的文件权限 | Microsoft Learn),发现其给出如下解释
在这里插入图片描述
即Windows访问Linux的文件的权限是由WSL分发版(如Ubuntu)的默认用户决定的,安装WSL分发版时会创建一个用户,一般会使用该用户登录,因此我们需要修改默认用户。

解决方案:

C:\Users\Administrator>ubuntu config --default-user rootC:\Users\Administrator>wsl -l -vNAME              STATE           VERSION
* Ubuntu            Running         2docker-desktop    Running         2C:\Users\Administrator>wsl
test@DESKTOP-KCURLDV:/mnt/c/Users/Administrator$ cat /etc/wsl.conf
[boot]
systemd=true[user]
default=test
test@DESKTOP-KCURLDV:/mnt/c/Users/Administrator$ vi /etc/wsl.conf
test@DESKTOP-KCURLDV:/mnt/c/Users/Administrator$ sudo vi /etc/wsl.conf
[sudo] password for test:
[boot]
systemd=true[user]
#default=test
test@DESKTOP-KCURLDV:/mnt/c/Users/Administrator$

在终端使用如下命令将默认用户变更为root(注意:ubuntu处需要根据你安装的Linux版本改变,可用如下命令查看你的Linux发行版名称),然后使用wsl命令打开Linux终端,正常来说就会以root用户登录,同时也可以直接在Windows的资源管理器中以root身份访问Linux文件。

拥有root权限可能会对虚拟机的安全造成威胁,例如从Windows入侵Linux文件系统。因此建议在执行完相关文件上传任务后,将默认用户改为普通用户(也可以改变需要访问的文件或文件夹的权限,例如sudo chmod 777 XXX,但会相对麻烦)。


C:\Users\Administrator>wsl -l -vNAME              STATE           VERSION
* Ubuntu            Running         2docker-desktop    Running         2如果执行以上命令后仍未变更默认用户,则可能是在Linux中使用了配置文件,使用如下命令查看并注释掉相关配置即可。(有时可能需要重启wsl)
```bashC:\Users\Administrator>wsl
test@DESKTOP-KCURLDV:/mnt/c/Users/Administrator$ cat /etc/wsl.conf
[boot]
systemd=true[user]
default=test
test@DESKTOP-KCURLDV:/mnt/c/Users/Administrator$ vi /etc/wsl.conf
test@DESKTOP-KCURLDV:/mnt/c/Users/Administrator$ sudo vi /etc/wsl.conf
[sudo] password for test:
[boot]
systemd=true[user]
#default=test
test@DESKTOP-KCURLDV:/mnt/c/Users/Administrator$ exit
logoutC:\Users\Administrator>wsl --terminate Ubuntu
操作成功完成。C:\Users\Administrator>wsl
root@DESKTOP-KCURLDV:/mnt/c/Users/Administrator#

5.4 编写test.go并运行

在这里插入图片描述

package mainimport "fmt"func main() {fmt.Println("Hello World")
}

在这里插入图片描述

在这里插入图片描述

如果出现报错
package test is not in GOROOT

解决:GO111MODULE修改为on
命令为go env -w GO111MODULE=on

root@DESKTOP-KCURLDV:~/aiops# go env
GO111MODULE="on" # 修改为on
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/root/.gvm/gos/go1.19"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/root/.gvm/gos/go1.19/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/aiops/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3377041513=/tmp/go-build -gno-record-gcc-switches"       

六、kind安装

Kind是Kubernetes In Docker的缩写,顾名思义,看起来是把k8s放到docker的意思。
kind创建k8s集群的基本原理就是:提前准备好k8s节点的镜像,通过docker启动容器,来模拟k8s的节点,从而组成完整的k8s集群。
需要注意,kind创建的集群仅可用于开发、学习、测试等
不能用于生产环境。

创建、启动k8s集群非常快速,资源消耗较低。
支持创建多节点的k8s集群,包括高可用模式。
kind 支持Linux,macos and windows
它是CNCF认证的k8s集群安装方式之一。
在这里插入图片描述安装kind:

root@DESKTOP-KCURLDV:~# gvm use go1.19
Now using version go1.19
root@DESKTOP-KCURLDV:~# go install sigs.k8s.io/kind@latest
go: downloading sigs.k8s.io/kind v0.27.0
go: downloading github.com/spf13/pflag v1.0.5
go: downloading github.com/spf13/cobra v1.8.0
go: downloading al.essio.dev/pkg/shellescape v1.5.1
go: downloading github.com/pkg/errors v0.9.1
go: downloading gopkg.in/yaml.v3 v3.0.1
go: downloading github.com/pelletier/go-toml v1.9.5
go: downloading github.com/mattn/go-isatty v0.0.20
go: downloading sigs.k8s.io/yaml v1.4.0
go: downloading github.com/BurntSushi/toml v1.4.0
go: downloading github.com/evanphx/json-patch/v5 v5.6.0
go: downloading github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2
go: downloading golang.org/x/sys v0.6.0
root@DESKTOP-KCURLDV:~# kind version
kind v0.27.0 go1.19 linux/amd64root@DESKTOP-KCURLDV:~# kind -h
kind creates and manages local Kubernetes clusters using Docker container 'nodes'Usage:kind [command]Available Commands:build       Build one of [node-image]completion  Output shell completion code for the specified shell (bash, zsh or fish)create      Creates one of [cluster]delete      Deletes one of [cluster]export      Exports one of [kubeconfig, logs]get         Gets one of [clusters, nodes, kubeconfig]help        Help about any commandload        Loads images into nodesversion     Prints the kind CLI versionFlags:-h, --help              help for kind-q, --quiet             silence all stderr output-v, --verbosity int32   info log verbosity, higher value produces more output--version           version for kindUse "kind [command] --help" for more information about a command.

七、使用kind实现单节点k8s集群部署

在这里插入图片描述
kind部署的k8s与docker中的k8s无关.

# kind create cluster --name k8s-1 --image kindest/node:v1.25.3Creating cluster "kind" ...✓ Ensuring node image (kindest/node:v1.25.16) 🖼✓ Preparing nodes 📦✓ Writing configuration 📜✓ Starting control-plane 🕹️✓ Installing CNI 🔌✓ Installing StorageClass 💾
Set kubectl context to "kind-kind"
You can now use your cluster with:kubectl cluster-info --context kind-kindNot sure what to do next? 😅  Check out https://kind.sigs.k8s.io/docs/user/quick-start/# kubectl cluster-info --context kind-kind
Kubernetes control plane is running at https://127.0.0.1:38317
CoreDNS is running at https://127.0.0.1:38317/api/v1/namespaces/kube-system/services/kube-dns:dns/proxyTo further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.# kind get clusters
kind# kubectl get node
NAME                 STATUS   ROLES           AGE     VERSION
kind-control-plane   Ready    control-plane   5m37s   v1.25.16# kubectl get po -n kube-system
NAME                                         READY   STATUS    RESTARTS        AGE
coredns-565d847f94-6kvst                     1/1     Running   0               6m
coredns-565d847f94-d7nt8                     1/1     Running   0               6m
etcd-kind-control-plane                      1/1     Running   0               6m12s
kindnet-cxk26                                1/1     Running   0               6m
kube-apiserver-kind-control-plane            1/1     Running   0               6m15s
kube-controller-manager-kind-control-plane   1/1     Running   1 (5m16s ago)   6m15s
kube-proxy-h8g6p                             1/1     Running   0               6m
kube-scheduler-kind-control-plane            1/1     Running   1 (5m18s ago)   6m12s# kind delete clusters kind 
Deleted nodes: ["kind-control-plane"]
Deleted clusters: ["kind"]

八、使用kind实现多节点k8s集群部署

# cat <<EOF > kind.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
EOF# kind create cluster --image kindest/node:v1.25.16 --name kind --config kind.yaml
Creating cluster "kind" ...✓ Ensuring node image (kindest/node:v1.25.16) 🖼✓ Preparing nodes 📦 📦 📦✓ Writing configuration 📜✓ Starting control-plane 🕹️✓ Installing CNI 🔌✓ Installing StorageClass 💾✓ Joining worker nodes 🚜
Set kubectl context to "kind-kind"
You can now use your cluster with:kubectl cluster-info --context kind-kindNot sure what to do next? 😅  Check out https://kind.sigs.k8s.io/docs/user/quick-start/# kubectl get node
NAME                 STATUS   ROLES           AGE    VERSION
kind-control-plane   Ready    control-plane   2m1s   v1.25.16
kind-worker          Ready    <none>          86s    v1.25.16
kind-worker2         Ready    <none>          85s    v1.25.16# cat <<EOF > kind1.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
networking:disableDefaultCNI: truekubeProxyMode: "ipvs"
EOF# kind create cluster --image kindest/node:v1.25.16 --name kind1 --config kind1.yaml
Creating cluster "kind1" ...✓ Ensuring node image (kindest/node:v1.25.16) 🖼✓ Preparing nodes 📦 📦 📦✓ Writing configuration 📜✓ Starting control-plane 🕹️✓ Installing StorageClass 💾✓ Joining worker nodes 🚜
Set kubectl context to "kind-kind1"
You can now use your cluster with:kubectl cluster-info --context kind-kind1Not sure what to do next? 😅  Check out https://kind.sigs.k8s.io/docs/user/quick-start/#kubectl config current-context
kind-kind1
#kubectl config use-context kind-kind# kind delete clusters kind1
Deleted nodes: ["kind1-control-plane" "kind1-worker2" "kind1-worker"]
Deleted clusters: ["kind1"]# kind delete clusters kind
Deleted nodes: ["kind-control-plane" "kind-worker2" "kind-worker"]
Deleted clusters: ["kind"]

也可以创建多套K8S集群
使用–name 指定集群名称
使用kubectl config use-context 集群上下文名称即可切换集群。

# cat <<EOF > kind2.yaml
# a cluster with 3 control-plane nodes and 3 workers
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: control-plane
- role: control-plane
- role: worker
- role: worker
- role: worker
EOF#kind create cluster --image kindest/node:v1.25.16 --name kind2 --config kind2.yaml
Creating cluster "kind2" ...✓ Ensuring node image (kindest/node:v1.25.16) 🖼✓ Preparing nodes 📦 📦 📦 📦 📦 📦✓ Configuring the external load balancer ⚖️✓ Writing configuration 📜✓ Starting control-plane 🕹️✓ Installing CNI 🔌✓ Installing StorageClass 💾✓ Joining more control-plane nodes 🎮✓ Joining worker nodes 🚜
Set kubectl context to "kind-kind2"
You can now use your cluster with:#kubectl cluster-info --context kind-kind2Not sure what to do next? 😅  Check out https://kind.sigs.k8s.io/docs/user/quick-start/
root@DESKTOP-KCURLDV:~# kubectl cluster-info --context kind-kind2Kubernetes control plane is running at https://127.0.0.1:41983
CoreDNS is running at https://127.0.0.1:41983/api/v1/namespaces/kube-system/services/kube-dns:dns/proxyTo further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.# kubectl get nodes
NAME                   STATUS   ROLES           AGE     VERSION
kind2-control-plane    Ready    control-plane   4m27s   v1.25.16
kind2-control-plane2   Ready    control-plane   3m53s   v1.25.16
kind2-control-plane3   Ready    control-plane   2m17s   v1.25.16
kind2-worker           Ready    <none>          83s     v1.25.16
kind2-worker2          Ready    <none>          83s     v1.25.16
kind2-worker3          Ready    <none>          83s     v1.25.16

九、通过goland开发 部署描述文件,并部署到k8s集群

关键字:月亮湾设计有限公司网站_html网页制作模板代码免费_推广搜索怎么选关键词_站内优化seo

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: