ubuntu安装kubernetes1.20

# 准备工作(所有节点操作)

1. 配置主机名

hostnamectl set-hostname cka01 --static
hostnamectl set-hostname cka02 --static
hostnamectl set-hostname cka03 --static

2. 修改/etc/hosts

#以master为例

vim /etc/hosts
192.168.0.180 cka01

3. 修改apt源

# 清空/etc/apt/sources.list,并添加如下内容
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
# 执行apt源更新操作
apt update -y

4. 清空防火墙规则

iptables -F

5. 修改内核参数

cat >/etc/sysctl.d/k8s.conf<<EOF

  net.ipv4.ip_forward = 1

  vm.swappiness = 0

EOF
sysctl -p /etc/sysctl.d/k8s.conf

6. 加载内核模块

cat > /etc/modules-load.d/modules.conf<<EOF

br_netfilter

ip_vs

ip_vs_rr

ip_vs_wrr

ip_vs_sh

nf_conntrack_ipv4

EOF

for i in br_netfilter ip_vs ip_vs_rr ip_vs_wrr ip_vs_sh nf_conntrack_ipv4;do modprobe $i;done

7. 安装docker

apt -y install apt-transport-https ca-certificates curl software-properties-common

curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

apt update -y
apt install docker-ce=5:19.03.15~3-0~ubuntu-bionic -y
mkdir -p /etc/docker
cat > /etc/docker/daemon.json<<EOF

{

    "exec-opts": ["native.cgroupdriver=systemd"],

    "log-driver": "json-file",

    "log-opts": {

        "max-size": "100m",

        "max-file": "10"

    },

    "registry-mirrors": ["https://pqbap4ya.mirror.aliyuncs.com"]

}

EOF

systemctl restart docker
systemctl enable docker

8. 安装kubeadm、kubectl、kubelet

apt-get update && apt-get install -y apt-transport-https

curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -

cat > /etc/apt/sources.list.d/kubernetes.list<<EOF

deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main

EOF

apt update -y

apt-cache madison kubelet

apt install -y kubelet=1.20.5-00  kubeadm=1.20.5-00  kubectl=1.20.5-00

# 安装master(只在master上操作)

kubeadm config print init-defaults  > kubeadm-config.yaml

apiVersion: kubeadm.k8s.io/v1beta2

bootstrapTokens:

- groups:

  - system:bootstrappers:kubeadm:default-node-token

  token: abcdef.0123456789abcdef

  ttl: 24h0m0s

  usages:

  - signing

  - authentication

kind: InitConfiguration

localAPIEndpoint:

  advertiseAddress: 192.168.0.180

  bindPort: 6443

nodeRegistration:

  criSocket: /var/run/dockershim.sock

  name: cka01

  taints:

  - effect: NoSchedule

    key: node-role.kubernetes.io/master

---

apiServer:

  timeoutForControlPlane: 4m0s

apiVersion: kubeadm.k8s.io/v1beta2

certificatesDir: /etc/kubernetes/pki

clusterName: kubernetes

controllerManager: {}

dns:

  type: CoreDNS

etcd:

  local:

    dataDir: /var/lib/etcd

imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers

kind: ClusterConfiguration

kubernetesVersion: v1.20.5

networking:

  dnsDomain: cluster.local

  serviceSubnet: 10.96.0.0/12

  podSubnet: 10.244.0.0/16

scheduler: {}

kubeadm init --config kubeadm-config.yaml

Your Kubernetes control-plane has initialized successfully!



To start using your cluster, you need to run the following as a regular user:



  mkdir -p $HOME/.kube

  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

  sudo chown $(id -u):$(id -g) $HOME/.kube/config



You should now deploy a pod network to the cluster.

Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:

  https://kubernetes.io/docs/concepts/cluster-administration/addons/



Then you can join any number of worker nodes by running the following on each as root:


# 部署网络插件


curl https://docs.projectcalico.org/manifests/calico.yaml -O

kubectl apply -f calico.yaml

# 添加节点

kubeadm join 192.168.0.180:6443 --token abcdef.0123456789abcdef \

    --discovery-token-ca-cert-hash sha256:d19eafe0f6ea680a75aca46bdedf9ea20da869a09ff5923d335277ff95d4094e


# 在所有节点设置kubelet开机自启动

systemctl enable kubelet

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值