手把手教你安装单Master的K8S集群

CKA学习之路


云原生时代,我们一起学习

文章目录

  • 系统环境
  • 服务器规划
  • 一、前置配置
  • 二、安装Docker和kubeadm/kubelet
  • 三、部署K8sMaster节点
  • 四、加入K8sNode节点
  • 五、部署容器网络(CNI)
  • 六、部署Dashboard

系统环境:

CentOS7.9
Docker20-ce
Kubernetes1.23

服务器规划:

192.168.1.186k8s-master
192.168.1.187k8s-node1
192.168.1.188k8s-node2

一、前置配置

1、执行yum update -y 更新服务器系统到最新

yum update -y

执行成功后,预期结果如图:

 2、关闭系统防护墙、Selinux、Swap分区(所有节点)

#关闭系统防火墙:
systemctl stop firewalld
systemctl disable firewalld
#关闭Selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config
#关闭Swap分区
sed -ri 's/.*swap.*/#&/' /etc/fstab

预期结果如下(截图仅为Master节点):

 在Master节点上添加上hosts

cat >> /etc/hosts << EOF
192.168.1.186 k8s-master
192.168.1.187 k8s-node1
192.168.1.188 k8s-node2
EOF

预期结果如图:

 将桥接的IPV4流量传递到iptables

cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

使配置生效:

sysctl --system

 配置后预期结果:

二、安装Docker、kubeadm、kubelet【所有节点】

1、安装Docker

#下载docker的阿里云安装源
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
#安装docker
yum -y install docker-ce
#设置为开机启动,并启动docker
systemctl enable docker && systemctl start docker

预期结果如下:

 配置Docker加速器

#配置docker加速
cat > /etc/docker/daemon.json << EOF
{
  "registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
#重启docker
systemctl restart docker
#查看docker信息

docker info

预期结果如下:

 3、配置阿里云yum 软件源,安装Kubeadm,kubelet,kubectl

cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

 4、安装指定版本的K8s,指定安装1.23.0版本

yum install -y kubelet-1.23.0 kubeadm-1.23.0 kubectl-1.23.0

安装过程:

 安装完成后的预期结果:

 添加开机启动

systemctl enable kubelet

 

三、部署K8SMaster节点

在规划好的主节点上执行

kubeadm init \
  --apiserver-advertise-address=192.168.1.186 \
  --image-repository registry.aliyuncs.com/google_containers \
  --kubernetes-version v1.23.0 \
  --service-cidr=10.96.0.0/12 \
  --pod-network-cidr=10.244.0.0/16 \
  --ignore-preflight-errors=all

安装过程:


安装好预期效果如下:

 注意:这一步安装的时候会有提示

[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get "http://localhost:10248/healthz": dial tcp [::1]:10248: connect: connection refused.

    Unfortunately, an error has occurred:
        timed out waiting for the condition

    This error is likely caused by:
        - The kubelet is not running
        - The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)

    If you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:
        - 'systemctl status kubelet'
        - 'journalctl -xeu kubelet'

    Additionally, a control plane component may have crashed or exited when started by the container runtime.
    To troubleshoot, list all containers using your preferred container runtimes CLI.

    Here is one example how you may list all Kubernetes containers running in docker:
        - 'docker ps -a | grep kube | grep -v pause'
        Once you have found the failing container, you can inspect its logs with:
        - 'docker logs CONTAINERID'

error execution phase wait-control-plane: couldn't initialize a Kubernetes cluster
To see the stack trace of this error execute with --v=5 or higher

这是没有直接临时关闭swap分区导致的,执行 swapoff -a  重新启动kubelet就好

#临时关闭swap分区
swapoff -a

 四、加入K8Snode节点

使用kubeadm将node节点加入集群(所有子节点都要执行):

kubeadm join 192.168.1.186:6443 --token rd8ymi.oeztlaletd9agkp0 \
	--discovery-token-ca-cert-hash sha256:b0c8918fc95faab2cc71d49a8f7ebde6902c4e5c60034f91252db6454f01c24c

 添加kubectl环境变量和认证,查看加入的node节点

mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
#查看node节点
kubectl get nodes

 目前节点还在准备中,并未运行

准备好的预期结果如图:

 注意:默认的token24小时内有效,超过24小时需要重新生成:

kubeadm token create --print-join-command

五、加入Calico(CNI)容器网络

calico是一个纯三层的数据网络中心方案,属于k8s主流的网络方案

下载yaml

wget https://docs.projectcalico.org/manifests/calico.yaml

下载后,部署calico

kubectl apply -f calico.yaml

查看calico的部署信息

 kubectl get pods -n kube-system

预期结果如图:

 六、部署Dashboard

Dashboard是k8s官方提供的一个UI,可以管理K8S 集群的资源

vi recommended.yaml
...
kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
spec:
  ports:
    - port: 443
      targetPort: 8443
      nodePort: 30001
  selector:
    k8s-app: kubernetes-dashboard
  type: NodePort
...

kubectl apply -f recommended.yaml
kubectl get pods -n kubernetes-dashboard

添加:

nodePort: 30001

type: NodePort

# 创建用户
kubectl create serviceaccount dashboard-admin -n kube-system
# 用户授权
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
# 获取用户Token
kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')

访问的地址是:http://masterip:30001

登录的时候使用获取的Token进行登录

登录预期如图:

欢迎大家关注我的公众号,一起学习运维、安全、开发相关的知识,一起加油,一起进步。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
手把手安装Jupyter Notebook,首先确保你已经有一个Python环境。因为Jupyter Notebook是基于Python的,所以你需要安装Python和pip(Python包管理器)。下面是安装Jupyter Notebook的基本步骤: **步骤1: 安装Python** - 访问官网 https://www.python.org/downloads/ 下载适合你操作系统的Python版本(推荐最新稳定版)。 - 完成安装后,打开命令行终端(Windows用户可以使用CMD或PowerShell,Mac/Linux用户用Terminal)。 **步骤2: 验证Python安装** - 在终端输入 `python --version` 或 `python3 --version`(取决于你的Python版本),检查是否显示正确的Python版本号。 **步骤3: 安装pip** - 如果Python已经自带pip,你可以跳过这一步。若不确定,输入 `python -m ensurepip --default-pip` 升级pip。 - 否则,访问 https://pip.pypa.io/en/stable/installation/ 官网获取安装指导。 **步骤4: 使用pip安装Jupyter Notebook** - 在终端中输入 `pip install jupyter notebook` 或 `pip3 install jupyter notebook`。 - 安装可能需要一段时间,根据网络速度和系统性能而定。 **步骤5: 启动Jupyter Notebook** - 安装完成后,输入 `jupyter notebook` 或 `jupyter notebook --notebook-dir=/path/to/save/notebooks` (如果你指定特定的目录保存笔记本)。 - 在浏览器中会弹出一个新的窗口,显示Jupyter Notebook的欢迎页面,你就可以开始创建、编辑和运行代码了。 **相关问题--:** 1. 如何检查Python是否已成功安装? 2. 安装Jupyter Notebook时遇到错误怎么办? 3. 如何配置Jupyter Notebook启动时自动打开浏览器?

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值