使用kubeadm部署kubernetes

安装docker

yum install -y docker

关闭swap

swapoff -a # 临时关闭
sed -ri 's/.*swap.*/#&/' /etc/fstab #永久关闭

修改hostname

hostnamectl set-hostname vm
PS: 如果不修改可能会导致name: Invalid value: "vm_0_16_centos": a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')错误,在kubeadm init时遇到该错误可以按照该方案修复。

修改kubeadm的资源地址

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

安装kubeadm

yum install -y kubelet-1.15.0 kubeadm-1.15.0 kubectl-1.15.0这里我使用的是1.15.0版本,可以不指定

部署kubernetes

kubeadm init --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16 --kubernetes-version v1.15.0 --ignore-preflight-errors=NumCPU,注意需要修改镜像仓库地址,这里的–ignore-preflight-errors=…是需要忽略的错误,我使用的虚拟机是单CPU的,不满足最低配置要求,添加NumCPU表示忽略该错误。

部署过程中可能会遇到如下错误:
  • [ERROR FileContent–proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1,执行echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptablesecho 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables解决。
  • [ERROR FileContent–proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1,执行echo "1" > /proc/sys/net/ipv4/ip_forward解决。
部署完成后按照提示配置config

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

部署pod

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml,如果虚拟机下载yaml文件失败可以手动下载后部署。

此时master就部署好了,如果仅用于测试可以通过kubectl taint nodes --all node-role.kubernetes.io/master-打开master节点参加工作负载,使用kubectl taint nodes k8s node-role.kubernetes.io/master=true:NoSchedule关闭。

测试

kubectl create deployment nginx --image=nginx部署nginx,通过kubectl get pods查看是否部署成功。
kubectl expose deployment nginx --port=80 --type=NodePort创建service,访问80端口,验证成功。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值