CentOS7安装单节点k8s
程序员文章站
2022-03-07 11:30:12
...
CentOS7安装单节点k8s
环境
- 本次安装使用, CPU: 1核, 内存: 2G, 系统: CentOS7.6
- 建议至少cpu: 2核 ,内存: 2G,非硬性要求,1核1G也可以搭建起集群
- 安装并运行docker
- 关闭swap
swapoff -a
- 把hostname的解析添加到hosts中
- 添加k8s yum软件源
# vi /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
- 安装 kubeadm, kubelet 和 kubectl
yum install -y kubelet kubernetes-cni kubeadm
- 配置kubeadm的yaml文件
# vi kubeadm.yaml
apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
kubernetesVersion: "v1.16.2"
imageRepository: "registry.aliyuncs.com/google_containers"
networking:
podSubnet: "10.244.0.0/16"
- 拉取镜像
kubeadm --config kubeadm.yaml config images pull
- 转换镜像的tag,根据自己下载的版本转换
docker tag registry.aliyuncs.com/google_containers/kube-proxy:v1.16.2 k8s.gcr.io/kube-proxy:v1.16.2
docker tag registry.aliyuncs.com/google_containers/kube-scheduler:v1.16.2 k8s.gcr.io/kube-scheduler:v1.16.2
docker tag registry.aliyuncs.com/google_containers/kube-apiserver:v1.16.2 k8s.gcr.io/kube-apiserver:v1.16.2
docker tag registry.aliyuncs.com/google_containers/kube-controller-manager:v1.16.2 k8s.gcr.io/kube-controller-manager:v1.16.2
docker tag registry.aliyuncs.com/google_containers/etcd:3.3.15-0 k8s.gcr.io/etcd:3.3.15-0
docker tag registry.aliyuncs.com/google_containers/coredns:1.6.2 k8s.gcr.io/coredns:1.6.2
docker tag registry.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1
- kubeadm初始化
kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=NumCPU
# --ignore-preflight-errors=NumCPU 忽略cpu错误,如果cpu核心数足够,可以不加.
# 必须要带上--pod-network-cidr=10.244.0.0/16,不然设置网络的时候会报错
# 如果初始化出错或者想重新初始化,可以使用如下命令
kubeadm reset
# 出现 Your Kubernetes master has initialized successfully!,安装成功
# 安装成功后执行
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
# 现在执行 kubectl get node,status为NotReady,是因为还没有网络插件
- 安装网络
kubectl apply -f https://github.com/coreos/flannel/raw/master/Documentation/kube-flannel.yml
- 安装Ingress
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml
#如果拥有公网ip,需要配置外网访问,请下载mandatory.yaml,添加, hostNetwork: true,位置如下:
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
hostNetwork: true #在此处添加
- 设置mater节点为可调度,因为默认情况下K8s的master节点是不能运行Pod
kubectl taint nodes --all node-role.kubernetes.io/master-
上一篇: 版式设计作品分析,优秀排版设计图片赏析
下一篇: 使用minikube快速搭建k8s环境