Kubesphere-学习笔记【入门篇】

目录

CentOS7配置篇

1. 安装

2. 配置静态ip

2.1 配置个人电脑的网络设置

2.2 配置VMware

2.3 配置服务器【电脑ip变更,则需重新配置】

2.X 更新yum

2.Y Centos移动/home目录空间到/根目录下

3. 配置ssh3.1 安装openssh-server

4. 配置openssl

单节点 All-in-One 模式安装 KubeSphere

0. 参考文章

1. 安装前准备

2. 安装KubeKey

3. 安装Kubernetes和kubesphere

4. 安装过程记录

5. 安装过程中问题记录

6. 后续运维常用命令

多节点安装 KubeSphere

0. 参考文章

1. 安装前准备

后记


CentOS7配置篇

1. 安装

  • 建议您的操作系统处于干净状态(不安装任何其他软件),否则可能会发生冲突。

分类
镜像 CentOS-7-x86_64-Everything-2009.iso
配置 Kubesphere-学习笔记【入门篇】_第1张图片
时区 选择亚洲、上海

选择带做桌面GNOME安装,软件选配如下。 

Kubesphere-学习笔记【入门篇】_第2张图片


2. 配置静态ip

2.1 配置个人电脑的网络设置

打开控制面板,具体路径:控制面板\网络和 Internet\网络连接

win11,具体路径:设置\网络和 Internet\高级网络设置\更多网络适配器

Kubesphere-学习笔记【入门篇】_第3张图片

2.2 配置VMware

Kubesphere-学习笔记【入门篇】_第4张图片

 Kubesphere-学习笔记【入门篇】_第5张图片

2.3 配置服务器【电脑ip变更,则需重新配置】

【步骤1】使用root用户,编辑ifcfg-ens33配置文件

su root
cd /etc/sysconfig/network-scripts/
cp ifcfg-ens33 backup_ifcfg-ens33
vim /etc/sysconfig/network-scripts/ifcfg-ens33
具体内容如下:

解释说明:IPADDR=192.168.109.140,填写的是:该服务器以后的静态ip。

[root@localhost hadoop]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR=192.168.109.140
NETMASK=255.255.255.0
GATEWAY=192.168.109.2
DNS1=192.168.109.2
DNS2=8.8.8.8
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=a8c3fa22-02e9-4465-b111-8d73b66a8311
DEVICE=ens33
ONBOOT=yes

---------------------------------------------------------------------------
【注意】参数值必须根据你个人的电脑环境设置。

BOOTPROTO=static  //设置静态ip  其中枚举值为dhcp、static、none(不指定,默认静态)
IPADDR=192.168.1.128    //ip地址,必须和主机一致
NETMASK=255.255.255.0    //子网掩码,必须和主机一致
GATEWAY=192.168.1.2        //网关,必须和主机一致
DNS1=8.8.8.8    
DNS2=114.114.114.114
 
ONBOOT=yes    //网络开机自启动

【步骤2】使用root用户编辑配置文件,观察DNS。

【注意】虚拟网络编辑器的子网ip和子网掩码一致,是你配置的vmnet8的首选DNS地址,即DNS1。而本人则配置为DNS1=192.168.109.2

vim /etc/resolv.conf

# 需要对应刚刚填写的DNS!!!!若少了则补上
[root@localhost hadoop]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 192.168.109.2
nameserver 8.8.8.8

【步骤3】验证结果

CentOS7重新加载网络配置

方案一:使用root用户执行命令nmcli c reload,然后reboot重启虚拟机
方案一:使用root用户 systemctl restart NetworkManager ,然后reboot重启虚拟机

重启完毕后,执行ifconfig 或 ip addr 查看ip地址确认是否已经静态IP。

上述操作每台服务器都要执行。

【注意】:若是在windows安装vmware,然后


安装centos虚拟机。计划在不同电脑上做镜像迁移,因为静态ip的原因虽然能正常登录centos,但是会连不上网,也ping 不通网络。所以也是要根据当前window的ip,做上述2.2和2.3章节适配。


2.X 更新yum

#本节为选做。
yum install -y yum-utils

#配置yum源为阿里云
yum-config-manager \
    --add-repo \
    http://mirros.aliyun.com/docker-ce/linux/centos/docker-ce.repo

#如果出错则选择如下
yum-config-manager \
    --add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

2.Y Centos移动/home目录空间到/根目录下

通过df-h发现,根目录只有50G,而home目录可用的,居然有131G。现在想分出100G给根目录。

Kubesphere-学习笔记【入门篇】_第6张图片

把你需要挂载的机器的逻辑卷记住(上面的图,左边是逻辑卷,右边是虚拟磁盘)

/dev/mapper/centos-home  就是物理地址(逻辑卷)

其中的centos就是这个类,不能修改,记住centos。
在第四步后要用,你的可能是叫其他名,都是df -h后显示的结果。
centos-home,取-前面的值。
用户为root
【第一步】:进行备份,一定要备份。
mkdir /home-bak
 
mv /home/* /home-bak

【第二步】:取消挂载,一定要询问使用这台机器的所有人,有没有在home下挂服务
umount /home 或者 umount -f /home

如果,不能取消,说明有其他程序在使用,找到他们,杀死他们。
查看谁在使用它
fuser -k /home 或者 fuser -m /home

然后,只复制前面的数字(进程号),可以通过【kill -9 数字】杀死

【第三步】:卸载逻辑卷
lvremove /dev/mapper/centos-home
 
Do you really want to remove active logical volume centos/home? [y/n]: y
  Logical volume "home" successfully removed


【第四步】:将空闲的空间移动80%到根目录下面
lvextend -l +85%FREE /dev/centos/root   

Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to <161.30 GiB (41292 extents).
  Logical volume centos/root successfully resized.
 

【第五步】:扩充到空间。期间df -h查看扩容的情况
xfs_growfs /dev/mapper/centos-root

[root@localhost /]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13107200 to 42283008

【第六步】:创建卷,为home目录,卷名为centos
lvcreate -L 110G -n home centos

【第七步】:将逻辑卷,拓展到磁盘系统,磁盘名字要与之前df-h的逻辑卷保持一致
mkfs -t xfs /dev/mapper/centos-home

[root@localhost /]# mkfs -t xfs /dev/mapper/centos-home
meta-data=/dev/mapper/centos-home isize=512    agcount=4, agsize=1286912 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=5147648, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

【第八步】:将磁盘系统的逻辑卷,与磁盘目录做映射
mount /dev/mapper/centos-home /home

[root@localhost /]# mount /dev/mapper/centos-home /home
mount: /dev/mapper/centos-home 已经挂载或 /home 忙
       /dev/mapper/centos-home 已经挂载到 /home 上

【第九步】:df -h查看扩容的情况
[root@localhost app]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                  18G     0   18G    0% /dev
tmpfs                     18G     0   18G    0% /dev/shm
tmpfs                     18G   13M   18G    1% /run
tmpfs                     18G     0   18G    0% /sys/fs/cgroup
/dev/mapper/centos-root  162G   24G  138G   15% /
/dev/sda1               1014M  185M  830M   19% /boot
/dev/sr0                 9.5G  9.5G     0  100% /run/media/webank/CentOS 7 x86_64
tmpfs                    3.6G     0  3.6G    0% /run/user/0
tmpfs                    3.6G   12K  3.6G    1% /run/user/42
/dev/mapper/centos-home   20G   33M   20G    1% /home

【第十步】:最后不要忘记,把/home-bak目录中备份的东西,还到/home里
mv /home-bak/* /home

参考文章:

https://blog.csdn.net/qq_35771266/article/details/115239147

Centos7把home目录下多余的空间转移到/根目录下_centos把home的空间分配给根目录_我要用代码向我喜欢的女孩表白的博客-CSDN博客

 取消挂载/home时出现umount: /home: device is busy。

取消挂载/home时出现umount: /home: device is busy,

原因是因为有程序在使用/home目录,我们可以使用fuser查看那些程序的进程,

然后杀掉就可以了。

[root@localhost home]# fuser -m /home

/home: 10278c 10279c 10280c 10281c 10282c 10295 10365 18222c

命令:kill -9 pid

其他还有很多命令:fuser -m /home

fuser -kvm /home

umount -f /home 强行解除挂载

umount命令

解挂文件系统。umount [-ahnrvV][-t 《文件系统类型》][文件系统]

umount可卸除目前挂在Linux目录中的文件系统。

线上在用的nfs访问时出了问题,导致/data1目录ls都无法进行输出,需要进行卸载掉 。而直接卸载时由于目录正被其他进程占用 ,无法直接umount,这里就结合fuser进行umount卸载。

1、直接卸载

[root@localhost /]# umount /data1/img

umount: /data1/img: device is busy

umount: /data1/img: device is busy

2、提示被占用,使用强制卸载

[root@localhost /]# umount -f /data1/img

umount2: Device or resource busy

umount: /data1/img: device is busy

umount2: Device or resource busy

umount: /data1/img: device is busy

注:使用-f 参数进行强制卸载时一般建议等一会儿再进行下面的操作,一些情况下处理需要1-2分钟的时间。

3、使用umount -f,问题依旧。使用fuser命令,先确认有那些进程在占用该目录

[root@localhost /]# fuser -cu /data1/img

/data1/img: 1757c(mysql)

上面查看发现是pid为1757的mysql用户起的进程在占用该目录。

4、确认mysql所起的进程可以kill 后,可以直接使用fuser 的k参数进行kill (也可以手动停掉1757进程再卸载)

[root@localhost /]# fuser -ck /data1/img

/data1/img: 1757c

注:这里k 就是kill的意思,注意没进行确认前要谨慎使用该参数。

另外,umount异常时,也经常会用到 lsof 指定确认文件被什么进程占用

上面就是Linux使用umount命令强制卸载文件系统的方法,即使提示被占用也照样能够通过命令来卸载。

kill -9 的实战图 

Kubesphere-学习笔记【入门篇】_第7张图片


3. 配置ssh
3.1 安装openssh-server

yum install -y openssl openssh-server

修改配置文件。用vim打开配置文件/etc/ssh/sshd_config。

vim /etc/ssh/sshd_config

---------------------------
#安装kubesphere所以设置
PermitRootLogin yes

MaxSessions 10

RSAAuthentication yes
PubkeyAuthentication yes

启动ssh的服务:
systemctl start sshd.service

设置开机自动启动ssh服务
systemctl enable sshd.service

查看ssh服务状态
systemctl status sshd.service 

补充:
重启ssh服务
systemctl restart sshd.service

4. 配置openssl

CentOS7,升级openssl。(本章节选配,)

有些时间,我们可能需要使用到openssl新版本的功能,但是centos的源目前没有提供那么新的版本,就需要自己更新了。

我这里就是需要使用openssl生成sm2的公钥私钥,需要升级到1.1.1。

升级方法
[root@node-21-243 deploy]# openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017
[root@node-21-243 deploy]# cd /usr/local/src
[root@node-21-243 src]# wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz
[root@node-21-243 src]tar xzvf ./OpenSSL_1_1_1c.tar.gz
[root@node-21-243 src]# cd openssl-OpenSSL_1_1_1c/
[root@node-21-243 openssl-OpenSSL_1_1_1c]# ./config
Operating system: x86_64-whatever-linux2
Configuring OpenSSL version 1.1.1c (0x1010103fL) for linux-x86_64
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub   ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   'Troubleshooting' section in the INSTALL file first)         ***
***                                                                ***
**********************************************************************

[root@node-21-243 openssl-OpenSSL_1_1_1c]# make
[root@node-21-243 openssl-OpenSSL_1_1_1c]# make install
[root@node-21-243 openssl-OpenSSL_1_1_1c]# mv /usr/bin/openssl /usr/bin/oldopenssl
[root@node-21-243 openssl-OpenSSL_1_1_1c]# ln -s /usr/local/bin/openssl /usr/bin/openssl
[root@node-21-243 openssl-OpenSSL_1_1_1c]# ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/
[root@node-21-243 openssl-OpenSSL_1_1_1c]# ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/
[root@node-21-243 openssl-OpenSSL_1_1_1c]# openssl version
OpenSSL 1.1.1c  28 May 2019


单节点 All-in-One 模式安装 KubeSphere

0. 参考文章

目的 链接
官方教程 在 Linux 上以 All-in-One 模式安装 KubeSphere
官方社区 All-in-One 模式安装失败 - KubeSphere 开发者社区
不错的文章 CentOS k8s1.20.9集群配套KubesPhere3.1.1安装_EssinZhang的博客-CSDN博客_centos 安装kubesphere
尚硅谷学习笔记 Kubernetes上安装KubeSphere · 语雀 (yuque.com)

1. 安装前准备

官网要求

  • 建议您的操作系统处于干净状态(不安装任何其他软件),否则可能会发生冲突。

(1)节点必须能够通过 SSH 连接。请见本文章的《配置ssh》

(2)节点可以使用 sudo、curl、openssl 命令。

(3)docker 可以由您自己安装或由 KubeKey 安装。注意:如果你想离线安装 KubeSphere,请务必提前安装好 docker。本人选择让Kubekey安装kubesphere自动安装docker

 下面的【必做】命令,务必实施。

## 0.禁用selinux【必做】 配置完需要重启reboot
vim /etc/sysconfig/selinux

## 安装kubesphere所以设置属性为disabled
SELINUX=disabled

## 1.关闭防火墙【必做】
systemctl stop firewalld && systemctl disable firewalld

## 2.安装socat、conntrack【必做】
yum install socat conntrack ebtables ipset

## 3.关闭selinux【选做】
#闭swap分区【虚拟内存】并且永久关闭虚拟内存
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
#关闭selinux
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

## 4.升级Linux内核为4.4的版本【选做】 这里升级内核是因为k8s在3.10的内核下不稳定,升级内核
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm
#安装内核(根据自己的需要选择内核版本)
# 阿里内核镜像仓库 http://mirrors.aliyun.com/elrepo/kernel/el7/x86_64/RPMS/
# 下载自己想要的rpm 我这里下载的4.4.245版本的内核
wget http://mirrors.aliyun.com/elrepo/kernel/el7/x86_64/RPMS/kernel-lt-4.4.245-1.el7.elrepo.x86_64.rpm
yum -y install  kernel-lt-4.4.245-1.el7.elrepo.x86_64.rpm
# 查看系统目前内核
awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
# 修改默认引导版本(0就是刚才查看的我新安装的内核序号)
grub2-set-default 0
#重启生效
reboot
#查看当前内核版本
uname -r 

## 6.调整系统临时区【必做】 --- 如果已经设置时区,可略过
#设置系统时区为中国/上海
timedatectl set-timezone Asia/Shanghai
#将当前的 UTC 时间写入硬件时钟
timedatectl set-local-rtc 0
#重启依赖于系统时间的服务
systemctl restart rsyslog
systemctl restart crond

## 7.关闭系统不需要的服务 【选做】
systemctl stop postfix && systemctl disable postfix

2. 安装KubeKey

# 1.配置安装目录
mkdir -p /app/kubesphere
chmod 777 /app/kubesphere
cd /app/kubesphere

# 2.先执行以下命令以确保从正确的区域下载 KubeKey
export KKZONE=cn

# 3.执行以下命令下载 KubeKey
curl -sfL https://get-kk.kubesphere.io | VERSION=v2.0.0 sh -

# 4.为kk添加可执行权限
chmod +x kk 或者 chmod 777 kk

3. 安装Kubernetes和kubesphere

## 1.先执行以下命令以确保从正确的区域下载 KubeKey
export KKZONE=cn

## 2.安装
./kk create cluster --with-kubernetes v1.21.5 --with-kubesphere v3.2.1

## 3.输入以下命令以检查安装结果。
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

#输出信息会显示 Web 控制台的 IP 地址和端口号,默认的 NodePort 是 30880。现在,您可以使用默认的帐户和密码 (admin/P@88w0rd) 通过 :30880 访问控制台。

4. 安装过程记录

1

5. 安装过程中问题记录

【报错1】

./kk create cluster --with-kubernetes v1.21.5 --with-kubesphere v3.2.1

发生如下报错
Failed to exec command: sudo -E /bin/bash -c “hostnamectl set-hostname Terry && sed -i ‘/127.0.1.1/s/.*/127.0.1.1 Terry/g’ /etc/hosts”

有网友说:“是不是本机没有开启ssh的服务。sudo systemctl start sshd”。

 【报错2】

./kk create cluster --with-kubernetes v1.21.5 --with-kubesphere v3.2.1

本人发生如下报错
error: Pipeline[CreateClusterPipeline] execute failed: Module[ETCDConfigureModule] exec failed: 
failed: [node1] [ExistETCDHealthCheck] exec failed after 20 retires: etcd health check failed: Failed to exec command: sudo -E /bin/bash -c "export ETCDCTL_API=2;export ETCDCTL_CERT_FILE='/etc/ssl/etcd/ssl/admin-node1.pem';export ETCDCTL_KEY_FILE='/etc/ssl/etcd/ssl/admin-node1-key.pem';export ETCDCTL_CA_FILE='/etc/ssl/etcd/ssl/ca.pem';/usr/local/bin/etcdctl --endpoints=https://192.168.19.188:2379 cluster-health | grep -q 'cluster is healthy'" 
Error:  client: etcd cluster is unavailable or misconfigured; error #0: EOF

 建议您的操作系统处于干净状态(不安装任何其他软件),否则可能会发生冲突。

-- 本人图方便,使用安装了tidb、mysql、java、flink等的服务器导致。

6. 后续运维常用命令

# 查看版本
kubectl version --short=true

# 验证安装结果
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

# 检查 KubeSphere 相关组件的运行状况
kubectl get pod --all-namespaces


多节点安装 KubeSphere

0. 参考文章

目的 链接
官方教程 在 Linux 上以 All-in-One 模式安装 KubeSphere
不错的文章 CentOS k8s1.20.9集群配套KubesPhere3.1.1安装_EssinZhang的博客-CSDN博客_centos 安装kubesphere
尚硅谷学习笔记 Kubernetes上安装KubeSphere · 语雀 (yuque.com)

1. 安装前准备

官网要求

  • 建议您的操作系统处于干净状态(不安装任何其他软件),否则可能会发生冲突。

(1)节点必须能够通过 SSH 连接。请见本文章的《配置ssh》

(2)节点可以使用 sudo、curl、openssl 命令。

(3)docker 可以由您自己安装或由 KubeKey 安装。注意:如果你想离线安装 KubeSphere,请务必提前安装好 docker。本人选择让Kubekey安装kubesphere自动安装docker

 下面的【比做】命令,务必实施。

# 1.关闭防火墙
systemctl stop firewalld && systemctl disable firewalld

# 2.置空iptables 
yum -y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables -F && service iptables save

# 3.关闭selinux
#闭swap分区【虚拟内存】并且永久关闭虚拟内存
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
#关闭selinux
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

# 4.升级Linux内核为4.4的版本  这里升级内核是因为k8s在3.10的内核下不稳定,升级内核(选做)
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm
#安装内核(根据自己的需要选择内核版本)
# 阿里内核镜像仓库 http://mirrors.aliyun.com/elrepo/kernel/el7/x86_64/RPMS/
# 下载自己想要的rpm 我这里下载的4.4.245版本的内核
wget http://mirrors.aliyun.com/elrepo/kernel/el7/x86_64/RPMS/kernel-lt-4.4.245-1.el7.elrepo.x86_64.rpm
yum -y install  kernel-lt-4.4.245-1.el7.elrepo.x86_64.rpm
# 查看系统目前内核
awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
# 修改默认引导版本(0就是刚才查看的我新安装的内核序号)
grub2-set-default 0

#重启生效
reboot
#查看当前内核版本
uname -r 

# 5.设置iptable
cat > kubernetes.conf <


后记

bye

你可能感兴趣的:(云原生,云原生,kubernetes)