kubernetes初始化

Posted hao-ran

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kubernetes初始化相关的知识,希望对你有一定的参考价值。

master

dokube.sh

#!/bin/sh
yum list wget &&
yum -y install wget &&
cd /etc/yum.repos.d/ &&
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo &&
cat >> /etc/yum.repos.d/kubernetes.repo <<EOF 
#!/bin/sh
#
[kubernetes]
name=kubernetes
baseurl=https://mirrors.huaweicloud.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgkey=https://mirrors.huaweicloud.com/kubernetes/yum/doc/rpm-package-key.gpg
gpgcheck=1
enables=1
EOF
yum clean all &&
yum repolist &&
yum list docker-ce kubectl kubelet kubeadm &&
yum -y install docker-ce kubeadm kubectl kubelet

echo > /etc/hostname <<EOF
mostre
EOF

hostname mostre &&
systemctl enable docker kubelet &&
mkdir -p /etc/docker &&

cat > /etc/docker/daemon.json <<EOF

"registry-mirrors": ["https://qijo5n63.mirror.aliyuncs.com"],
 "exec-opts": ["native.cgroupdriver=systemd"]

EOF

systemctl daemon-reload &&
systemctl start docker &&

echo "1" > /proc/sys/net/bridge/bridge-nf-call-iptables

echo "1" > /proc/sys/net/bridge/bridge-nf-call-ip6tables 

systemctl disable firewalld &&
systemctl stop firewalld &&



swapoff -a &&

cat  > /etc/sysconfig/kubelet <<EOF
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
EOF

systemctl enable docker kubelet &&

/bin/sh -x /root/kubeadminit.sh

kubeadminit.sh

#!/bin/sh
KUBE_VERSION=`kubelet --version | awk -F ' ' 'print $2'`
list=$(kubeadm config images list --kubernetes-version=$KUBE_VERSION)
for line in $list
do
echo $line
# docker pull $line
image=`echo $line | awk ' sub(/k8s.gcr.io/,"gcr.azk8s.cn/google_containers"); print $0 '`
echo $image
docker pull $image
docker tag $image $line
docker rmi $image
done &&


kubeadm init --kubernetes-version=v1.14.2  --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap &&

# --pod-network-cidr=10.244.0.0/16 绒布网络使用

mkdir -p $HOME/.kube &&
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config &&

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

# docker pull quay.azk8s.cn/coreos/flannel:v0.11.0-amd64 &&
# docker tag quay.azk8s.cn/coreos/flannel:v0.11.0-amd64 quay.io/coreos/flannel:v0.11.0-amd64 &&

# cd &&
# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.11.0/Documentation/kube-flannel.yml &&

node1

#!/bin/sh
yum list wget &&
yum -y install wget &&
cd /etc/yum.repos.d/ &&
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo &&
cat >> /etc/yum.repos.d/kubernetes.repo <<EOF 
#!/bin/sh
#
[kubernetes]
name=kubernetes
baseurl=https://mirrors.huaweicloud.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgkey=https://mirrors.huaweicloud.com/kubernetes/yum/doc/rpm-package-key.gpg
gpgcheck=1
enables=1
EOF
yum clean all &&
yum repolist &&
yum list docker-ce kubectl kubelet kubeadm &&
yum -y install docker-ce kubeadm kubectl kubelet

echo > /etc/hostname <<EOF
node1
EOF

hostname node1 &&
systemctl enable docker kubelet &&
mkdir -p /etc/docker &&

cat > /etc/docker/daemon.json <<EOF

"registry-mirrors": ["https://qijo5n63.mirror.aliyuncs.com"],
 "exec-opts": ["native.cgroupdriver=systemd"]

EOF

systemctl daemon-reload &&
systemctl start docker &&

echo "1" > /proc/sys/net/bridge/bridge-nf-call-iptables

echo "1" > /proc/sys/net/bridge/bridge-nf-call-ip6tables 

systemctl disable firewalld &&
systemctl stop firewalld &&



swapoff -a &&

cat  > /etc/sysconfig/kubelet <<EOF
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
EOF

systemctl enable docker kubelet &&

/bin/sh -x /root/kubemirror.sh

kubemirror.sh

#!/bin/sh
KUBE_VERSION=`kubelet --version | awk -F ' ' 'print $2'`
list=$(kubeadm config images list --kubernetes-version=$KUBE_VERSION)
for line in $list
do
echo $line
# docker pull $line
image=`echo $line | awk ' sub(/k8s.gcr.io/,"gcr.azk8s.cn/google_containers"); print $0 '`
echo $image
docker pull $image
docker tag $image $line
docker rmi $image
done

node2

dokube.sh

#!/bin/sh
yum list wget &&
yum -y install wget &&
cd /etc/yum.repos.d/ &&
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo &&
cat >> /etc/yum.repos.d/kubernetes.repo <<EOF 
#!/bin/sh
#
[kubernetes]
name=kubernetes
baseurl=https://mirrors.huaweicloud.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgkey=https://mirrors.huaweicloud.com/kubernetes/yum/doc/rpm-package-key.gpg
gpgcheck=1
enables=1
EOF
yum clean all &&
yum repolist &&
yum list docker-ce kubectl kubelet kubeadm &&
yum -y install docker-ce kubeadm kubectl kubelet

echo > /etc/hostname <<EOF
node2
EOF

hostname node2 &&
systemctl enable docker kubelet &&
mkdir -p /etc/docker &&

cat > /etc/docker/daemon.json <<EOF

"registry-mirrors": ["https://qijo5n63.mirror.aliyuncs.com"],
 "exec-opts": ["native.cgroupdriver=systemd"]

EOF

systemctl daemon-reload &&
systemctl start docker &&

echo "1" > /proc/sys/net/bridge/bridge-nf-call-iptables

echo "1" > /proc/sys/net/bridge/bridge-nf-call-ip6tables 

systemctl disable firewalld &&
systemctl stop firewalld &&



swapoff -a &&

cat  > /etc/sysconfig/kubelet <<EOF
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
EOF

systemctl enable docker kubelet &&

/bin/sh -x /root/kubemirror.sh

kubemirror.sh

#!/bin/sh
KUBE_VERSION=`kubelet --version | awk -F ' ' 'print $2'`
list=$(kubeadm config images list --kubernetes-version=$KUBE_VERSION)
for line in $list
do
echo $line
# docker pull $line
image=`echo $line | awk ' sub(/k8s.gcr.io/,"gcr.azk8s.cn/google_containers"); print $0 '`
echo $image
docker pull $image
docker tag $image $line
docker rmi $image
done

IP=ip addr show enp0s3 | grep inet | grep -v inet6 | awk ‘print $2‘ | awk -F ‘/‘ ‘print $1‘

以上是关于kubernetes初始化的主要内容,如果未能解决你的问题,请参考以下文章

ubuntu 安装 kubernetes

kubeadm初始化kubernetes报错以及解决

关于Kubernetes-v1.23.6-master节点的初始化操作

kubernetes初始化

使用 kubeadm 创建一个 kubernetes 集群

Kubernetes(k8s)快速入门和部署