侧边栏壁纸
博主头像
里奥的博客博主等级

行动起来,活在当下

  • 累计撰写 24 篇文章
  • 累计创建 7 个标签
  • 累计收到 2 条评论

目 录CONTENT

文章目录

在Debian中使用 Kind 搭建Kubernetes 集群

里奥
2024-05-17 / 0 评论 / 0 点赞 / 29 阅读 / 4361 字

简介

kind 让你能够在本地计算机上运行 Kubernetes。 使用这个工具需要你安装 Docker 或者 Podman

kind 的 Quick Start 页面展示开始使用 kind 所需要完成的操作。

安装

第一步,下载kind

# For AMD64 / x86_64
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.23.0/kind-linux-amd64

第二步, 移动kind文件

将下载好的二进制文件移动到/usr/local/bin/文件夹下

sudo mv ./kind /usr/local/bin/kind

第三步, 配置PATH环境变量

这里因为使用的是zsh, 所以修改的是.zshrc, 如果你使用的是bash. 请修改.bashrc

第四步, 使用配置文件创建cluster

默认创建出来的集群名字为 kind, 如果想自定义集群名字,可以使用--name 是可选参数

kind create cluster --config=kindcluster.yaml

下面为创建集群时的配置文件kindcluster.yaml

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  kubeadmConfigPatches:
  - |
    kind: InitConfiguration
    nodeRegistration:
      kubeletExtraArgs:
        node-labels: "ingress-ready=true"
  extraPortMappings:
  - containerPort: 80
    hostPort: 80
    protocol: TCP
  - containerPort: 443
    hostPort: 443
    protocol: TCP
- role: worker
- role: worker

创建成功后如下面所示, 可以使用kubectl get nodes 来获取所有的节点来确认是否创建成功

可能的问题

端口已经被占用

解决方法:

使用netstat -tulpn命令查看端口状态, 可以看到80 端口的确是被占用了

注: 如果没有netstat命令,可以使用 sudo apt install net-tools 安装

在浏览器中输入localhost, 发现是Debian的默认的Apache服务器在占用

使用命令sudo systemctl disable apache2 && sudo systemctl stop apache2禁用Apache

参考文档

  1. kind (k8s.io)

  2. 安装工具 | Kubernetes

  3. GitHub - kubernetes-sigs/kind: Kubernetes IN Docker - local clusters for testing Kubernetes

  4. How do I stop Apache from starting on Linux? - nixCraft (cyberciti.biz)

0

评论区