k8s部署

主机名节点ip角色部署
master192.168.176.189master
node06192.168.176.191node
node07192.168.176.192node

一、设置hosts解析

操作节点:所有节点,以node6 为例

修改hostsname,以及hosts文件

1、# master
[root@master sysctl.d]# hostnamectl set-hostname master
2、# node节点同上
3、[root@node06 ~]# vim /etc/hosts

二、系统设置

操作节点:所有节点,以node6 为例

1、设置iptables

[root@node06 ~]# iptables -vnL
[root@node06 ~]# iptables -F
[root@node06 ~]# iptables -P FORWARD ACCEPT

2、关闭swap

[root@node06 ~]# swapoff  -a
#防止开机自启
[root@master k8s]# sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

3、关闭selinux跟防火墙

[root@node07 ~]# getenforce 
[root@node07 ~]# vim /etc/selinux/config 
[root@node07 ~]# systemctl stop firewalld
[root@node07 ~]# systemctl disable firewalld

 4、修改内核参数

[root@node06 ~]# cat <<EOF >  /etc/sysctl.d/k8s.conf
> net.bridge.bridge-nf-call-ip6tables = 1   #开启桥设备内核监控(ipv6)
> net.bridge.bridge-nf-call-iptables = 1   # 开启桥设备内核监控(ipv4)
> net.ipv4.ip_forward=1                      # 开启路由转发
> EOF
[root@node06 ~]# modprobe br_netfilter
[root@node06 ~]# sysctl -p /etc/sysctl.d/k8s.conf
[root@node06 ~]# sysctl --system

 5、配置yum源

# 该步骤可直接上阿里云镜像官网获取

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
yum clean all && yum makecache

三、安装docker

操作节点:所有节点

[root@node07 ~]# yum install -y docker-ce

配置docker镜像加速

[root@node06 sysctl.d]# mkdir -p /etc/docker
[root@node06 sysctl.d]# vim /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "registry-mirrors" : ["https://8xpk5wnt.mirror.aliyuncs.com"]
}

[root@master sysctl.d]# systemctl enable docker && systemctl start docker

 四、部署k8s

1、安装kubeadm、kubelet、kubectl

操作节点:所有

[root@master sysctl.d]# yum install -y  kubelet kubeadm kubectl
[root@master sysctl.d]# systemctl enable kubelet
[root@master ~]# yum install -y ipvsadm ipset

2、初始化配置文件

操作节点:master

[root@master ~]# kubeadm config print init-defaults > kubeadm.yaml
[root@master ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  kubeadm.yaml
[root@master ~]# cat kubeadm.yaml 

apiVersion: kubeadm.k8s.io/v1beta3
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 192.168.176.189   # apiserver 的IP地址
  bindPort: 6443
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  imagePullPolicy: IfNotPresent
  name: master
  taints: null
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns: {}
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: registry.aliyuncs.com/google_containers  # 镜像仓库地址
kind: ClusterConfiguration
kubernetesVersion: 1.22.0
networking:
  dnsDomain: cluster.local
  podSubnet: 10.244.0.0/16   # 容器地址cidr,新添加
  serviceSubnet: 10.96.0.0/12    # 服务地址cidr
scheduler: {}
# 以下4行新增
--- 
apiVersion: kubeproxy.config.k8s.io/v1alpha1  
kind: KubeProxyConfiguration
mode: ipvs

3、镜像提前获取

操作节点:master

# 查看需要的镜像列表
[root@master k8s]# kubeadm config images list --config kubeadm.yaml
registry.aliyuncs.com/google_containers/kube-apiserver:v1.22.0
registry.aliyuncs.com/google_containers/kube-controller-manager:v1.22.0
registry.aliyuncs.com/google_containers/kube-scheduler:v1.22.0
registry.aliyuncs.com/google_containers/kube-proxy:v1.22.0
registry.aliyuncs.com/google_containers/pause:3.5
registry.aliyuncs.com/google_containers/etcd:3.5.0-0
registry.aliyuncs.com/google_containers/coredns:v1.8.4
#获取
[root@master k8s]# kubeadm config images pull --config kubeadm.yaml

 4、初始化master节点

操作节点:master

[root@master k8s]#  kubeadm init --config=kubeadm.yaml | tee master-init.log

5、 根据提示创建文件

操作节点:master

[root@master ~]# mkdir -p /root/.kube
[root@master ~]# cp -i /etc/kubernetes/admin.conf /root/.kube/config

而后,查看

[root@master ~]# kubectl  get  componentstatuses
[root@master k8s]# kubectl version

 若是提示改错误,则修改配置文件,将端口0 注释

Warning: v1 ComponentStatus is deprecated in v1.19+
NAME                 STATUS      MESSAGE                                                                                       ERROR
scheduler            Unhealthy   Get "http://127.0.0.1:10251/healthz": dial tcp 127.0.0.1:10251: connect: connection refused   
[root@master ~]# cd /etc/kubernetes/manifests/
[root@master ~]# vim kube-controller-manager.yaml 
[root@master ~]# vim kube-scheduler.yaml

  五、node加入集群

操作节点:node6 node7

[root@node06 ~]# kubeadm join 192.168.176.189:6443 --token abcdef.0123456789abcdef \
> --discovery-token-ca-cert-hash sha256:1e6fb98ede07e86315fdc0c3c9c8c38b30f468a45799149c49ee9082724fc49b

随后在master上查看

[root@master docker]# kubectl get nodes
NAME     STATUS     ROLES                  AGE   VERSION
master   NotReady   control-plane,master   69m   v1.22.3
node06   NotReady   <none>                 46s   v1.22.3
node07   NotReady   <none>                 31s   v1.22.3

 六、添加flannel

地址:https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

[root@master ~]# kubectl apply -f kube-flannel.yml
[root@master ~]# kubectl get nodes
NAME     STATUS   ROLES                  AGE     VERSION
master   Ready    control-plane,master   3h24m   v1.22.3
node06   Ready    <none>                 136m    v1.22.3
node07   Ready    <none>                 135m    v1.22.3
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值