K8S 单机部署
作者:互联网
系统初始化
1、关闭selinux
setenforce 0 && sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
2、关闭默认防火墙
systemctl stop firewalld && systemctl disable firewalld
3、设置hostname
hostnamectl --static set-hostname master
echo master > /etc/hosts
cat >> /etc/hosts << OG
> 192.168.228.131 master
> OG
4、修改内核参数和模块
cat <<EOF > /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF #使内核参数配置生效 sysctl --system && modprobe br_netfilter && lsmod | grep br_netfilter
5、关闭交换内存,如果不关闭,kubelet服务将无法启动
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
6、安装docker 、建议改成国内的源,速度比较快
yum -y install yum-utils device-mapper-persistent-data lvm2 yum-config-manager -y --add-repo https://download.docker.com/linux/centos/docker-ce.repo yum -y install docker-ce-18.06.3.ce-3.el7 docker-ce-cli-18.06.3.ce-3.el7 containerd.io systemctl start docker && systemctl enable docke
7、设置国内docker仓库
cat <<EOF > /etc/docker/daemon.json { "registry-mirrors": [ "https://3laho3y3.mirror.aliyuncs.com" ] } EOF systemctl restart docker
8、配置kubernetes yum源,用以安装Kubernetes基础服务及工具,此处使用阿里云镜像仓库源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo [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 yum makecache fast
9、安装Kubernetes基础服务及工具
yum -y install kubelet-1.13* kubeadm-1.13* kubectl-1.13* systemctl start kubelet systemctl enable kubelet.service
10、下载k8s相关镜像并打标签
for i in `kubeadm config images list`; do imageName=${i#k8s.gcr.io/} docker pull registry.aliyuncs.com/google_containers/$imageName docker tag registry.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName docker rmi registry.aliyuncs.com/google_containers/$imageName done;
11、初始化k8s和网络
kubeadm init --kubernetes-version=v1.13.12 --pod-network-cidr=10.100.0.0/16 --ignore-preflight-errors=all #安装成功标志 #Your Kubernetes master has initialized successfully! #开机启动 && 启动服务 systemctl enable kubelet && systemctl start kubelet
12、初始化kubectl配置
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config kubectl apply -f https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')
13、默认k8s的master节点是不能跑pod的业务,需要执行以下命令解除限制
kubectl taint nodes --all node-role.kubernetes.io/master- #如果不允许调度 #kubectl taint nodes master1 node-role.kubernetes.io/master=:NoSchedule #污点可选参数 NoSchedule: 一定不能被调度 PreferNoSchedule: 尽量不要调度 NoExecute: 不仅不会调度, 还会驱逐Node上已有的Pod
14、查看主节点运行 Pod 的状态
kubectl get pods --all-namespaces -o wide
标签:kubernetes,单机,部署,--,systemctl,yum,&&,docker,K8S 来源: https://www.cnblogs.com/libruce/p/16478042.html