k8s安装(一键安装和多节点安装)

本文档详细介绍了如何在Ubuntu 22.04.3操作系统上进行Kubernetes(k8s)的一键安装和多节点安装过程,包括设置本机环境、安装Docker、配置k8s前置条件、单节点allinone安装、多节点部署、配置config-sample.yaml、Nginx配置以及如何进行SSH 22端口映射和卸载k8s。
摘要由CSDN通过智能技术生成

操作系统

utuntu 22.04.3

//记得添加host配置,karma 是我的主机名,可根据自己的修改

vim /etc/hosts

192.168.9.15 karma 

本机环境

su root
//更新软件源
sudo apt update 
//升级软件源
sudo apt upgrade
//安装网络
apt install ifupdown
apt install network-manager
apt install net-tools
//开启时间同步
sudo apt install ntp
sudo systemctl status ntp
sudo systemctl start ntp
sudo systemctl enable ntp
date
//设置时区
sudo timedatectl set-timezone Asia/Shanghai

安装docker

//安装证书
apt-get install ca-certificates curl gnupg lsb-release
//安装证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
//设置阿里云
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
//安装docker最新版
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
//当前用户加入docker组
sudo usermod -aG docker $USER
//启动docker
systemctl start docker
//安装工具
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
//重启
service docker restart
//测试
sudo docker run hello-world
//查看版本
sudo docker version
//查看镜像
sudo docker images

//从阿里云镜像获取
登录阿里云,在控制台中搜索:容器镜像服务
获得:https://xxxx.mirror.aliyuncs.com

//镜像加速
https://kubesphere.io/zh/docs/v3.4/faq/installation/configure-booster/
sudo mkdir -/etc/docker
sudo vi /etc/docker/daemon.json
{
  "registry-mirrors": ["https://xxxx.mirror.aliyuncs.com"]
}
sudo systemctl daemon-reload
sudo systemctl restart docker

k8s 前置

//安装必要工具
sudo apt install ebtables socat conntrack ipset
//下载kk
https://github.com/kubesphere/kubekey/releases/download/v3.2-alpha.1-console/kubekey-v3.2-alpha.1-console-linux-amd64.tar.gz
tar -zxvf 'kubekey-v3.2-alpha.1-console-linux-amd64 (1).tar.gz'
//授权
chmod +x kk
//设置中国区域
export KKZONE=cn

单节点安装allinone

参考:https://kubesphere.io/zh/docs/v3.4/quick-start/all-in-one-on-linux/
//设置中国区域
export KKZONE=cn
//安装
./kk create cluster --with-kubernetes v1.22.12 --with-kubesphere v3.4.0
//查看日志
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)-o jsonpath='{.items[0].metadata.name}') -f

多节点安装

· 

参考:https://kubesphere.io/zh/docs/v3.4/installing-on-linux/introduction/multioverview/
//设置中国区域
export KKZONE=cn
//创建配置文件
./kk create config --with-kubesphere v3.4.0 --with-kubernetes v1.22.12
./kk create config --with-kubesphere v3.3.2 --with-kubernetes v1.23.7
//配置参考官网即可
//安装
./kk create cluster -f config-sample.yaml


程序会自动把当前节点的主机名设置为当前登录主机名,记得加ip映射,然后重启,比当前节点名称masternode,要在/etc/hosts 添加 192.168.9.15 masternode

config-sample.yaml(其余部分保持默认),

spec:
  hosts:
  - {name: masternode, address: 192.168.9.15, internalAddress: 192.168.9.15, user: karma, password: "5C35BA0F86A595CE83B955FF679BAF3B"}
  roleGroups:
    etcd:
    - masternode
    control-plane:
    - masternode
    worker:
    - masternode

nginx配置

server {
    listen 8080;
    server_name 192.168.9.15;

    location / {
        proxy_pass http://192.168.9.15:30880;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    location /login {
        proxy_pass http://192.168.9.15:30880/login;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

nginx配置主机ssh 22端口映射

stream {
    server {
        listen 8081;
        proxy_pass localhost:22;
    }
}

卸载

./kk delete cluster
./kk delete cluster [-f config-sample.yaml]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

karma_angel

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值