Create kubernetes use kubeadm
root needed
ubuntu
1apt-get update && apt-get install -y apt-transport-https
2curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
3cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
4deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
5EOF
6apt-get update
7apt-get install -y kubelet kubeadm kubectl
8#close swap
9swapoff -a
10#remove swap mount
11vi /etc/fstab
apt-key is deprecated in some new version linux distribution, like ubuntu, put gpg file inside /etc/apt/trusted.gpg.d
fedora
1cat <<EOF > /etc/yum.repos.d/kubernetes.repo
2[kubernetes]
3name=Kubernetes
4baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
5enabled=1
6gpgcheck=1
7repo_gpgcheck=1
8gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
9EOF
10#close selinux
11setenforce 0
12#disable selinux
13sed -i 's/SELINUX=enforcing/SELINUX=disabled/g'
14#disable firewalld
15systemctl disable firewalld.service
16
17dnf update && dnf install -y kubelet kubeadm kubectl
18systemctl enable --now kubelet
19#close swap
20swapoff -a
21#disable swap
22dnf remove zram-generator-defaults
config
1apiVersion: kubeadm.k8s.io/v1beta3
2bootstrapTokens:
3 - groups:
4 - system:bootstrappers:kubeadm:default-node-token
5 token: abcdef.0123456789abcdef
6 ttl: 24h0m0s
7 usages:
8 - signing
9 - authentication
10kind: InitConfiguration
11localAPIEndpoint:
12 #apiserver address
13 advertiseAddress: 192.168.1.2
14 bindPort: 6443
15nodeRegistration:
16 # use containerd, docker is deprecated
17 criSocket: unix:///var/run/containerd/containerd.sock
18 imagePullPolicy: IfNotPresent
19 # node must visis
20 name: node
21 taints: null
22---
23apiServer:
24 timeoutForControlPlane: 4m0s
25apiVersion: kubeadm.k8s.io/v1beta3
26certificatesDir: /etc/kubernetes/pki
27clusterName: kubernetes
28controllerManager: {}
29imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers
30dns: {}
31etcd:
32 external:
33 # external etcd, you may use etcd provide by kubeadm
34 endpoints:
35 - https://192.168.1.2:2379
36 caFile: /etc/etcd/pki/ca.crt
37 certFile: /etc/etcd/pki/apiserver-etcd-client.crt
38 keyFile: /etc/etcd/pki/apiserver-etcd-client.key
39
40kind: ClusterConfiguration
41# latest version
42kubernetesVersion: 1.24.1
43networking:
44 dnsDomain: cluster.local
45 # here we use flannel cni plugin, you may change you use others such as calico
46 podSubnet: 10.244.0.0/16
47 serviceSubnet: 10.96.0.0/12
48scheduler: {}
you can use
kubeadm config print init-defaults
print the latest version
change kernel param
1cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
2br_netfilter
3overlay
4EOF
5
6cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
7net.bridge.bridge-nf-call-ip6tables = 1
8net.bridge.bridge-nf-call-iptables = 1
9net.ipv4.ip_forward=1
10EOF
maybe need load immediately
1modprobe br_netfilter overlay
1#pull image first
2kubeadm config images pull --config kubeadm-init-config.yaml
3#init
4kubeadm init --config kubeadm-init-config.yaml
5#allow single node cluster run pod
6kubectl taint nodes --all node-role.kubernetes.io/control-plane- node-role.kubernetes.io/master-
1mkdir $HOME/.kube && sudo cp /etc/kubenertes/admin.conf $HOME/.kube/config
2kubectl get node
you will see k8s pod runing