一、创建配置文件
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=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
二、安装kubelet kubeadm kubectl
安装命令:yum install -y kubelet kubeadm kubectl --nogpgcheck
启动 systemctl enable kubelet && systemctl start kubelet
三、修改网络配置(看情况)
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
关闭交换机:getenforce
关闭selinux
四、初始化Master
配置文件:kubeadm config print init-defaults > kubeadm-init.yaml
该文件有两处需要修改: 将 advertiseAddress: 192.168.0.4 修改为本机地址
将 imageRepository: k8s.gcr.io 修改为 imageRepository: registry.aliyuncs.com/google_containers
执行初始化 : kubeadm init --config kubeadm-init.yaml
出现端口被占用情况
kubeadm reset
kubeadm init --config kubeadm-init.yaml --ignore-preflight-errors=Swap
验证过:
kubeadm init --apiserver-advertise-address=172.18.153.1 --pod-network-cidr=10.244.0.0/16 --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --ignore-preflight-errors=Swap
--加入master的方法
kubeadm join 172.18.153.1:6443 --token puuw2o.0bjj0n6bt799b7bo \
--discovery-token-ca-cert-hash sha256:c448c75b6c23678c3f4fa92ae34eca956b52af618467e471cc19efaf120df2b5
五、异常解决方法
1.查看IP地址:ifconfig, --apiserver-advertise-address= IP
2,containerd问题
docker pull registry.aliyuncs.com/google_containers/pause:3.6
containerd config default > /etc/containerd/config.toml 获取配置文件,修改成:sandbox_image=registry.aliyuncs.com/google_containers/pause:3.6
systemctl restart containerd
systemctl status containerd.service
3.查看异常文件
journalctl -u kubelet >b
4,etcd启动报错,会出现访问127.0.0.1:2379这个访问不到的问题
--listen-client-urls=https://0.0.0.0:2379,https://0.0.0.0:2379(这里改成0.0.0.0)
- --listen-metrics-urls=http://127.0.0.1:2381
- --listen-peer-urls=https://0.0.0.0:2380(这里改成0.0.0.0)
先准备好一个etcd.yaml 文件,再执行初始化的时候,就以最快的速度一直强制修改/etc/kubernetes/manifests/下的文件,这样才能让启动的docker读到对的配置cp -rf etcd.yaml /etc/kubernetes/manifests/
六、环境配置
这个是node节点需要做的
kubeadm join 192.168.0.1:6443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash
sha256:4158c5823bc89d10a310533473f506342d93ee9255c7d9331300bf5fe4251cev
配置环境, 让当前用户可以执行kubectl命令
配置kubectl执行命令环境
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
## 执行kubectl命令查看机器节点
kubectl get node
标签:kubernetes,--,0.0,init,com,kubeadm,k8s,安装 From: https://www.cnblogs.com/wushaoliang/p/17880436.html