k8s安装(初学者)首次安装

命令帮助:
查看节点 kubectl get nodes -n kube-system
查看pod: kubectl get pods -n kube-system
查看详情 :kubectl describe pod 名称 -n kube-system
查看添加集群命令 kubeadm token create --print-join-command

本来打算用天翼云的,但是443端口需要备案,无语了,没法用
环境:2台机器
一台阿里云:106.14.250.* 172.21.244.105
一台腾讯云:110.42.134.* 172.17.0.3
节点开发:master开放6443 443 node开放 10250
步骤
1.关闭防火墙
systemctl stop firewalld
systemctl disable firewalld

2.关闭selinux
sed -i ‘s/enforcing/disabled’ /etc/selinux/config #永久
setenforce 0 #临时

3.关闭swap
swapoff -a #临时
sed -i ‘/ swap / s/^(.*)$/#\1/g’ /etc/fstab #永久

4.修改hosts (izuf6cc5ecqsvemt5p6tz阿里云主机名,izuffsdfdsfqsvemt5p6tz腾讯云)
cat >> /etc/hosts << EOF
106.14.250.* 172.21.244.105 izuf6cc5ecqsvemt5p6tz
110.42.134.* 172.17.0.3 izuffsdfdsfqsvemt5p6tz
EOF

5修改网桥
cat < /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF #永久

sysctl net.bridge.bridge-nf-call-iptables=1 #临时
sysctl net.bridge.bridge-nf-call-ip6tables=1 #临时

6.同步时间,可以用date命令查看时间是否同步

7.安装docker,版本是要19的,我的是19.03,本来是20的,不行
增加配置
/etc/docker/daemon.json {
“registry-mirrors”:[ “https://registry.docker-cn.com”,
“https://docker.mirrors.ustc.edu.cn”,
“http://hub-mirror.c.163.com”,
“https://cr.console.aliyun.com/”
],
“exec-opts”:[“native.cgroupdriver=systemd”]
}
重启服务 systemctl restart docker.service
开机启动 systemctl enable docker.service

8.设置k8s的阿里云yum源
cat < /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
EOF

9.安装kubeadm,kubelet,kubectl
yum install kubelet-1.19.4 kubeadm-1.19.4 kubectl–1.19.4 -y
开机启动 systemctl enable kubelet.service

10.设置规则(公网IP一定要,要不通不了)
主节点: iptables -t nat -A OUTPUT -d <主节点公网IP> -j DNAT --to-destination <主节点私有IP>
node节点: iptables -t nat -A OUTPUT -d <主节点私有IP> -j DNAT --to-destination <主节点公网IP>

11.初始化,在master执行
kubeadm init --image-repository registry.aliyuncs.com/google_containers
–pod-network-cidr=10.244.0.0/16
–apiserver-advertise-address=172.21.244.105 -v=10 #内网IP,公网IP会失败

12.执行下面命令,初始化后面会有提示,注意查看
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown ( i d − u ) : (id -u): (idu):(id -g) $HOME/.kube/config

13 安装 pod 网络附加组件 flannel
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yml

14查看node节点中是否存在/run/systemd/resolve/resolv.conf,不存在看master节点是否有(我就是拷贝master),然后到任何一个目录下面创建resolv.conf拷贝master的内容,namespace的IP地址查看 /etc/resolv.conf,然后用cp命令复制到/run/systemd/resolve/resolv.conf

15 加入集群
kubeadm join 172.31.0.199:6443
–token e8p9qk.xnltu0891oulluzy
–discovery-token-ca-cert-hash sha256:85dd6782c077b45ffb25c55cd98cf41d2093728ba296996ec2d94b2d851fbe6f
–cri-socket=/run/containerd/containerd.sock
-v=10

暂时结果,后面继续学习
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值