Windows主机中构建适用于K8S Operator开发环境

news/2024/6/3 19:26:00 标签: windows, kubernetes, 容器

基于 win 10 打造K8S应用开发环境

一、wsl子系统安装

在cmd命令行终端或powershell中操作

windows_8">1.1 确认windows操作系统版本

在这里插入图片描述

在这里插入图片描述

1.2 开启wsl功能

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

1.3 wsl配置

PS C:\Users\cpf> wsl

提示:
    适用于 Linux 的 Windows 子系统没有已安装的分发版。
    可以通过访问 Microsoft Store 来安装分发版:
    https://aka.ms/wslstore
PS C:\Users\cpf> wsl --help

获取命令使用帮助
PS C:\Users\cpf> wsl --set-default-version 2

提示:
    有关与 WSL 2 的主要区别的信息,请访问 https://aka.ms/wsl2
操作成功完成。
PS C:\Users\cpf> wsl --update

提示:
  正在安装: 适用于 Linux 的 Windows 子系统
  已安装 适用于 Linux 的 Windows 子系统。
PS C:\Users\cpf> wsl

提示:
  适用于 Linux 的 Windows 子系统没有已安装的分发。

  使用‘wsl.exe --list --online’列出可用的分发
  和 ‘wsl.exe --install <Distro>’进行安装。
PS C:\Users\cpf> wsl --list --online
无法从'https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json'提取列表分发。无法解析服务器的名称或地址
Error code: Wsl/WININET_E_NAME_NOT_RESOLVED

注:科学上网后

PS C:\Users\cpf> wsl --list --online

提示如下:

以下是可安装的有效分发的列表。
使用‘wsl.exe --install <Distro>'安装。

NAME               FRIENDLY NAME
Ubuntu             Ubuntu
Debian             Debian GNU/Linux
kali-linux         Kali Linux Rolling
SLES-12            SUSE Linux Enterprise Server v12
SLES-15            SUSE Linux Enterprise Server v15
Ubuntu-18.04       Ubuntu 18.04 LTS
Ubuntu-20.04       Ubuntu 20.04 LTS
Ubuntu-22.04       Ubuntu 22.04 LTS
OracleLinux_8_5    Oracle Linux 8.5
OracleLinux_7_9    Oracle Linux 7.9
PS C:\Users\cpf> wsl --install
适用于 Linux 的 Windows 子系统已安装。
以下是可安装的有效分发的列表。
使用‘wsl.exe --install <Distro>'安装。

NAME               FRIENDLY NAME
Ubuntu             Ubuntu
Debian             Debian GNU/Linux
kali-linux         Kali Linux Rolling
SLES-12            SUSE Linux Enterprise Server v12
SLES-15            SUSE Linux Enterprise Server v15
Ubuntu-18.04       Ubuntu 18.04 LTS
Ubuntu-20.04       Ubuntu 20.04 LTS
Ubuntu-22.04       Ubuntu 22.04 LTS
OracleLinux_8_5    Oracle Linux 8.5
OracleLinux_7_9    Oracle Linux 7.9
安装一个发行版
PS C:\Users\cpf> wsl --install -d Ubuntu
正在安装: Ubuntu
已安装 Ubuntu。
正在启动 Ubuntu...

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-sP6OBe7U-1684921594607)(Windows主机中构建适用于K8S Operator开发环境.assets/image-20230209123449122.png)]

PS C:\Users\cpf> wsl --install -d Ubuntu-22.04

正在安装: Ubuntu 22.04 LTS
[==========================68.0%========                   ]
PS C:\Users\cpf> wsl -l

提示如下:

适用于 Linux 的 Windows 子系统分发:
Ubuntu (默认)
PS C:\Users\cpf> wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Stopped         2
PS C:\Users\cpf> wsl --set-default Ubuntu
操作成功完成。
输入子系统名称,直接启动一个子系统,此步骤不是必须的。
PS C:\Users\cpf> Ubuntu

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
msb@DESKTOP-OO4CNVS:~$
关闭所有
PS C:\Users\cpf> wsl --shutdown

关闭指定发行版本
PS C:\Users\cpf> wsl -t Ubuntu

查看是否停止
PS C:\Users\cpf> wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Stopped         2
卸载已安装

PS C:\Users\cpf> wsl --unregister Ubuntu

二、docker-desktop安装

2.1 下载

https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe?utm_source=docker&utm_medium=webreferral&utm_campaign=dd-smartbutton&utm_location=module

2.2 安装及设置

在这里插入图片描述

运行docker desktop
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

三、Golang安装

3.1 安装gvm

msb@DESKTOP-OO4CNVS:~$ bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)


输出:
Cloning from https://github.com/moovweb/gvm.git to /home/msb/.gvm
No existing Go versions detected
Installed GVM v1.0.22

Please restart your terminal session or to get started right away run
 `source /home/msb/.gvm/scripts/gvm

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

msb@DESKTOP-OO4CNVS:~$ gvm

Could not find bison

  linux: apt-get install bison

Could not find gcc

  linux: apt-get install gcc

Could not find make

  linux: apt-get install make

ERROR: Missing requirements.

3.2 golang安装

msb@DESKTOP-OO4CNVS:~$ sudo apt-get install bison gcc make

msb@DESKTOP-OO4CNVS:~$ sudo apt-get install curl git mercurial make binutils bison gcc build-essential
msb@DESKTOP-OO4CNVS:~$ gvm listall
msb@DESKTOP-OO4CNVS:~$ gvm install go1.19 -B
msb@DESKTOP-OO4CNVS:~$ gvm list

gvm gos (installed)

go1.19
msb@DESKTOP-OO4CNVS:~$ gvm use go1.19
Now using version go1.19
msb@DESKTOP-OO4CNVS:~$ gvm list

gvm gos (installed)

=> go1.19
msb@DESKTOP-OO4CNVS:~$ gvm uninstall go1.19

四、kubectl安装

默认可以不用安装,直接把docker desktop中附加过来使用即可。

root@DESKTOP-OO4CNVS:~# curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
root@DESKTOP-OO4CNVS:~# chmod +x kubectl
root@DESKTOP-OO4CNVS:~# mv kubectl /usr/local/bin/
root@DESKTOP-OO4CNVS:~# kubectl version

五、goland安装及配置

官方文档 https://www.jetbrains.com/help/go/how-to-use-wsl-development-environment-in-product.html#local_project

由于我们已经安装并配置好golang了,所以从这里开始就可以 https://www.jetbrains.com/help/go/how-to-use-wsl-development-environment-in-product.html#create_project_for_wsl

golang的一些环境信息可以使用此命令查看

在这里插入图片描述

填写项目位置

\\wsl$\Ubuntu\home\zhshl\aiops
填写GOROOT

\\wsl$\Ubuntu\home\.gvm\gos\go1.20.3

在这里插入图片描述

在这里插入图片描述

报如下错误时:

package test is not in GOROOT
root@DESKTOP-OO4CNVS:~# go env


输出如下内容:
root@DESKTOP-OO4CNVS:~# go env
GO111MODULE="" 需要修改位置
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/.gvm/pkgsets/go1.19/global/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/.gvm/pkgsets/go1.19/global"
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="0"
GOMOD="/dev/null"
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4022425319=/tmp/go-build -gno-record-gcc-switches"
go env -w GO111MODULE=on
root@DESKTOP-OO4CNVS:~# go env

输出内容如下:

GO111MODULE="on" 修改位置
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/.gvm/pkgsets/go1.19/global/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/.gvm/pkgsets/go1.19/global"
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="0"
GOMOD="/dev/null"
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build524401627=/tmp/go-build -gno-record-gcc-switches"
root@DESKTOP-OO4CNVS:~# vim aiops/test.go
root@DESKTOP-OO4CNVS:~# cat aiops/test.go
package main

import "fmt"

func main() {
                fmt.Println("hello");
}
root@DESKTOP-OO4CNVS:~# go run aiops/test.go
hello

六、kind安装

Kind是Kubernetes In Docker的缩写,顾名思义,看起来是把k8s放到docker的意思。没错,kind创建k8s集群的基本原理就是:提前准备好k8s节点的镜像,通过docker启动容器,来模拟k8s的节点,从而组成完整的k8s集群。需要注意,kind创建的集群仅可用于开发、学习、测试等,不能用于生产环境。
创建、启动k8s集群非常快速,资源消耗较低。
支持创建多节点的k8s集群,包括高可用模式。
kind 支持 Linux, macOS and Windows
它是CNCF认证的k8s集群安装方式之一

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-IVDCSvZg-1684921594611)(Windows主机中构建适用于K8S Operator开发环境.assets/562987-20220114201905023-573450383.png)]

root@DESKTOP-OO4CNVS:~# go install sigs.k8s.io/kind@latest
root@DESKTOP-OO4CNVS:~# kind version
kind v0.17.0 go1.19 linux/amd64

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

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-740SQvVx-1684921594611)(Windows主机中构建适用于K8S Operator开发环境.assets/image-20230213155110943.png)]

kind create cluster --image kindest/node:v1.25.3
Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.25.3) 🖼
 ✓ 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-kind

Not sure what to do next? 😅  Check out https://kind.sigs.k8s.io/docs/user/quick-start/
root@DESKTOP-OO4CNVS:~# kind get clusters
kind
root@DESKTOP-OO4CNVS:~# kind delete clusters kind
Deleted clusters: ["kind"]

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

root@DESKTOP-OO4CNVS:~# cat cluster.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
root@DESKTOP-OO4CNVS:~# kind create cluster --config cluster.yaml
Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.25.3) 🖼
 ✓ 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-kind

Thanks for using kind! 😊
root@DESKTOP-OO4CNVS:~# kubectl get nodes
NAME                 STATUS   ROLES           AGE    VERSION
kind-control-plane   Ready    control-plane   2m5s   v1.25.3
kind-worker          Ready    <none>          101s   v1.25.3
kind-worker2         Ready    <none>          88s    v1.25.3
# vim cluster.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
  - role: worker
  - role: worker
networking:
  disableDefaultCNI: true
  kubeProxyMode: "ipvs"

也可以创建多套K8S集群

使用–name 指定集群名称

使用kubectl config use-context 集群上下文名称即可切换集群。


http://www.niftyadmin.cn/n/356640.html

相关文章

Prompt Engineering | 对话聊天prompt

&#x1f604; 使用LLM来搭建一个定制的聊天机器人&#xff0c;只需要很少的工作量。 ⭐ 本文将讲解如何利用聊天格式与个性化或专门针对特兹那个任务或行为的聊天机器人进行多伦对话。 文章目录 1、提供对话的早期部分&#xff0c;引导模型继续聊天2、示例&#xff1a;构建一个…

深入理解 SOCKS5 代理和网络安全

在当今信息时代&#xff0c;网络安全问题日益突出&#xff0c;对于企业和个人而言&#xff0c;保护隐私和数据安全至关重要。为了达到这一目标&#xff0c;许多人选择使用 SOCKS5 代理服务来保护自己的在线活动。本文将深入探讨 SOCKS5 代理的工作原理、优势以及网络安全方面的…

PIC18F26单片机波特率配置

只需要配置以下三个寄存器&#xff1a; BRGCON1 BRGCON2 BRGCON3 BRGCON10x07; > 0000 0111 BRGCON20x90; > 1001 0000 BRGCON30x42; > 0101 0010 BRGCON1&#xff1a; Sync_Sog (bit7~bit6)1TQ,BRP(bit5~bit0)1 &#xff0c;则TQ((2*(BRP1))/Fosc16/32M&am…

QT桌面(实现界面的滑动切换)

文章目录 前言一、使用QStackedLayout管理主界面二、重写鼠标处理事件总结 前言 在ARM Linux中使用QT如何实现滑动翻页切换界面的效果呢&#xff1f;在ARM中是没有自带的鼠标的&#xff0c;那么我们如何实现滑动翻页呢&#xff1f;经过测试发现在ARM中运行QT程序也是可以通过重…

03-AJAX-jQuery实现方式

1、$.ajax()&#xff1a;用于执行 Ajax 请求的最常用方法。它可以设置请求类型、请求 URL、请求参数等。 $.ajax({type: 请求类型,url: 请求 URL,data: { 请求数据 },dataType: 返回数据类型,beforeSend: function () {},success: function (response) {},error: function (XM…

ubuntu换镜像源(ubuntu换源)

ubuntu换镜像源&#xff08;ubuntu换源&#xff09; 文章目录 ubuntu换镜像源&#xff08;ubuntu换源&#xff09;1. 备份镜像源文件2. 根据不同 ubuntu 版本设置不同的镜像源2.1 focal 版本镜像源2.2 bionic 版本镜像源2.3 ubuntu 自带源&#xff1a; 参考文献 1. 备份镜像源文…

HTTPS和SSH的区别

这里写目录标题 1.什么是HTTPS&#xff1f;2.什么是SSH&#xff1f;3.两者的区别1.用途不同2.实现方式不同3.加密算法不同4.安全级别不同 4.总结 1.什么是HTTPS&#xff1f; HTTPS是一种网络通信协议&#xff0c;全称为“Hyper Text Transfer Protocol Secure”&#xff0c;即…

一、阿里云oss

文章目录 一、阿里云oss1、开通“对象存储OSS”服务1.1创建Bucket1.2上传默认头像1.3获取用户acesskeys 2、使用SDK文档3、文件服务实现3.1搭建service-oss模块3.1.1 搭建service-oss模块3.1.2 修改配置3.1.3 启动类3.1.4配置网关 3.2 测试SDK3.3封装service接口3.4封装control…