1分钟创建k8s 集群 create kubernetes cluster in 1 minute

网友投稿 275 2022-10-27

1分钟创建k8s 集群 create kubernetes cluster in 1 minute

设置集群的主机名字,我是k8s用于centos8,k7s用于centos7的配置

setup local host name centos8

cat <> /etc/hosts 192.168.99.103 k8smaster 192.168.99.104 k8snode1 192.168.99.105 k8snode2 EOF

setup local host name centos7

cat <> /etc/hosts 192.168.99.107 k7smaster 192.168.99.108 k7snode1 192.168.99.109 k7snode2 EOF

禁止防火墙开启VxLan穿透

disable firewall & selinux and enable transparent masquerading (VxLan)

systemctl stop firewalld systemctl disable firewalld setenforce 0 sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux modprobe br_netfilter

禁止swap,开启iptable 桥(如果有)

setup bridge iptables rules & disable memory swap

cat < /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sysctl --system swapoff -a yes | cp -rf /etc/fstab /etc/fstab_bak cat /etc/fstab_bak |grep -v swap > /etc/fstab cat /etc/fstab

禁用ipv6

disable ipv6 on centos7

cat </etc/sysctl.conf net.ipv6.conf.all.disable_ipv6 =1 net.ipv6.conf.default.disable_ipv6 =1 EOF sysctl -w net.ipv6.conf.all.disable_ipv6=1 sysctl -w net.ipv6.conf.default.disable_ipv6=1

安装docker

install docker on centos8

dnf config-manager --add-repo=dnf install dnf install docker-ce --nobest -y systemctl start docker systemctl enable docker docker version docker images

install docker on centos7

sudo yum install -y yum-utils yum-config-manager \ --add-repo \ yum install -y docker-ce docker-ce-cli containerd.io systemctl start docker systemctl enable docker docker version docker images

安装repo 禁用selinux

add k8s repo and install

cat <

可以选择性安装不同班的kubeadm,默认用最新

#option install different version kubeadm

#yum list --showduplicates kubeadm --disableexcludes=kubernetes #yum install -y kubelet-1.18.8-0 --disableexcludes=kubernetes #yum install -y kubectl-1.18.8-0 --disableexcludes=kubernetes #yum install -y kubeadm-1.18.8-0 --disableexcludes=kubernetes #systemctl enable --now kubelet #systemctl status kubelet -l

customer config.yaml

cat < /var/lib/kubelet/config.yaml apiVersion: kubelet.config.k8s.io/v1beta1 authentication: anonymous: enabled: false webhook: cacheTTL: 0s enabled: true x509: clientCAFile: /etc/kubernetes/pki/ca.crt authorization: mode: Webhook webhook: cacheAuthorizedTTL: 0s cacheUnauthorizedTTL: 0s clusterDNS: - 10.10.0.10 clusterDomain: cluster.local cpuManagerReconcilePeriod: 0s evictionPressureTransitionPeriod: 0s fileCheckFrequency: 0s healthzBindAddress: 127.0.0.1 healthzPort: 10248 0s imageMinimumGCAge: 0s kind: KubeletConfiguration nodeStatusReportFrequency: 0s nodeStatusUpdateFrequency: 0s rotateCertificates: true runtimeRequestTimeout: 0s staticPodPath: /etc/kubernetes/manifests streamingConnectionIdleTimeout: 0s syncFrequency: 0s volumeStatsAggPeriod: 0s cgroupDriver: systemd EOF

有几率if you have iptable error

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

change cgroup

sed -i 's/cgroup-driver=systemd/cgroup-driver=cgroupfs/g' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf systemctl daemon-reload && systemctl restart kubelet journalctl -f -u kubelet.service

init cluster in master node

kubeadm init --kubernetes-version=1.18.8 \ --apiserver-advertise-address=192.168.99.107 \ --service-cidr=10.10.0.0/16 \ --pod-network-cidr=10.122.0.0/16 \ --v=5

kube config prep

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

install kuberouter

kubectl apply -f cluster in worker node

kubeadm join 192.168.99.107:6443 --token 81r96h.f0yj1z6l23gt0emh \ --discovery-token-ca-cert-hash sha256:567f3f2a5e3630d6063c954bda42f094dcdcdb93bc6ea620a73299dcb30ddfae \ --v=6

3 nodes cluster

install calico network instead of kubernetes cni

kubectl apply -f init \ --apiserver-advertise-address=192.168.99.107 \ --pod-network-cidr=10.122.0.0/16 \ --v=5 mkdir -p $HOME/.kube cp -i /etc/kubernetes/admin.conf $HOME/.kube/config chown $(id -u):$(id -g) $HOME/.kube/config echo export KUBECONFIG=~/.kube/config>> ~/.bashrc source ~/.bashrc kubectl apply -f join 192.168.99.107:6443 --token s0buim.93oefcuj5bglxl8k \ --discovery-token-ca-cert-hash sha256:55fa1f22b8679d8617e70cb8ff6827034e3eaadb0c72cb095337520ca513dcf4

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:PC104总线与DSP数据通信接口设计
下一篇:Spring Security安全框架之记住我功能
相关文章

 发表评论

暂时没有评论,来抢沙发吧~