centos安装k8s

1. 前置

俩台centos服务器,不过多说明,教程基于centos

2. hosts配置

我这样配置,最后没发现那块有联动,望大佬更正

vim /etc/hosts
在末尾添加
192.***** master
192.*** note

3. 防火墙

说是要关闭防火墙,我俩台服务器都是基于内网,没有防火墙,所以没执行该操作

systemctl stop firewalld NetworkManager
systemctl disable firewalld NetworkManager

4. swap

swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

5. yum源更新

curl  -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl  -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
sed -i '/aliyuncs/d' /etc/yum.repos.d/*.repo

yum clean all && yum makecache fast

6. ntp时间同步

#查看当前时间
date 
#
yum install chrony -y
systemctl start chronyd
systemctl enable chronyd
# 同步时间
ntpdate -u ntp.aliyun.com
# 将硬件时钟设置为当前的系统时间
hwclock -w
#

7. 修改linux内核参数,开启数据包转发功能

# 数据包转发
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward=1
vm.max_map_count=262144
EOF


modprobe br_netfilter
# 加载读取内核参数配置文件
sysctl -p /etc/sysctl.d/k8s.conf

8. 安装docker

yum remove docker docker-common docker-selinux docker-engine -y 

curl -o /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum list docker-ce --showduplicates
# 看是指定为该版本
yum install docker-ce-19.03.15 docker-ce-cli-19.03.15 -y

mkdir -p /etc/docker
#阿里云加速地址取阿里云申请
cat > /etc/docker/daemon.json <<'EOF'
{
  "registry-mirrors" : ["阿里云加速地址"],
    "exec-opts":["native.cgroupdriver=systemd"]
}
EOF

#启动
systemctl start docker && systemctl enable docker

docker version

9. k8s所有节点配置

curl -o /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
        http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
# 安装k8s 1.19.3版本
yum install kubelet-1.19.3 kubeadm-1.19.3   kubectl-1.19.3 ipvsadm -y

# 查看k8s的版本
kubeadm version

# 设置开机自启
systemctl enable kubelet

10 主节点初始化

kubeadm init \
--apiserver-advertise-address=主节点ip地址 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.19.3 \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16 \
--service-dns-domain=cluster.local \
--ignore-preflight-errors=Swap \
--ignore-preflight-errors=NumCPU



#添加其他命令
yum install bash-completion -y
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc

会报错,请参照下面记录的一些坑

11. 子节点加入

主节点init时,会打印再控制台
kubeadm join ******:6443 --token vf7bng.p0lkay3nygloh561
–discovery-token-ca-cert-hash

重新生成token

kubeadm token create --print-join-command

12. flannel节点网络通信(子节点通信)

下载版本:https://github.com/coreos/flannel.git 上传到服务器 或者git clone --depth 1 https://github.com/coreos/flannel.git 拉取

unzip flannel-master.zip
cd flannel-master/Documentation
# 查看当前使用网卡
ifconfig

vim  kube-flannel.yml 
#查询到kube-flannel,添加 --iface=eth0
####################################
      containers:
      - name: kube-flannel
        image: docker.io/rancher/mirrored-flannelcni-flannel:v0.19.2
        command:
        - /opt/bin/flanneld
        args:
        - --ip-masq
        - --kube-subnet-mgr
        - --iface=eth0
##################################
保存退出
#执行创建
kubectl create -f ./kube-flannel.yml 
# 
kubectl apply -f kube-flannel.yml
# docker查询flannel是否安装成功
docker ps |grep flannel

docker中存在flannel

在这里插入图片描述

flannel安装完成之后,节点通信

在这里插入图片描述

13 安装nginx测试

vim nginx-k8s.yml
#########开始###################
apiVersion: v1
kind: Pod
metadata:
  name: mine-nginx
spec:
  containers:
  - image: nginx:1.14.1
    name: test-container
    ports:
    - containerPort: 80
      hostPort: 8081
    volumeMounts:
    - mountPath: /mine-nginx
      name: nginx-volume
  volumes:
  - name: nginx-volume
    hostPath:
      path: /opt/yml
 #########结束###################

# 执行创建命令
kubectl create -f nginx-k8s.yml
# 查看
kubectl get pod 

正在构建中

在这里插入图片描述

如果一直再pending中

kubectl describe pod mine-nginx

发现报错

Events:
  Type     Reason            Age                  From               Message
  ----     ------            ----                 ----               -------
  Warning  FailedScheduling  79s (x5 over 5m38s)  default-scheduler  0/1 nodes are available: 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.

解决:

kubectl taint nodes --all node-role.kubernetes.io/master-

构建完成

在这里插入图片描述

子节点ip:8081

在这里插入图片描述

会使用的命令(持续更新)

1. kubectl get nodes  #查询当前所有节点
2. kubectl get nodes -owide #查询当前节点的详细信息
3. kubectl get pod #查询启动的容器
4. kubectl get pod -n kube-system #查询容器插件执行状态

  1. The connection to the server localhost:8080 was refused - did you specify the right host or port?

echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
source ~/.bash_profile

  1. Unable to update cni config: no networks found in /etc/cni/net.d

yum reinstall -y kubernetes-cni --nogpgcheck
//flannel-0.19.2/Documentation
kubectl apply -f kube-flannel.yml
  1. kubeamd init 长时间未响应
1.一种是配置的阿里镜像源没有剩下
4. 网络问题,波动太大无法持续的下载docker容器
  1. The connection to the server localhost:8080 was refused - did you specify the right host or port?
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
 
source ~/.bash_profile
 
kubectl get nodes
 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值