kubadmin K8s简易安装

https://www.cnblogs.com/superlinux/p/12582009.html

基础准备[ALL]

# 1. 关闭防火墙功能
systemctl stop firewalld
systemctl disable firewalld

# 2.关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config 
setenforce 0

# 3. 关闭swap
swapoff -a
#或将命令加入开机启动
echo "swapoff -a" >>/etc/profile

# 4. 服务器规划 ip和主机名按照实际情况
cat > /etc/hosts << EOF
192.168.26.134 k8smaster1
192.168.26.135 k8snode1
192.168.26.136 k8snode2
EOF

#5. 主机名配置:
 hostnamectl set-hostname  k8smaster1
 bash

#6. 时间同步配置
yum install -y ntpdate
ntpdate time.windows.com
ntpdate ntp.aliyun.com

#开启转发
cat > /etc/sysctl.d/k8s.conf << EOF 
net.bridge.bridge-nf-call-ip6tables = 1



EOF
echo "net.bridge.bridge-nf-call-iptables = 1" >> /etc/sysctl.d/k8s.conf 
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.d/k8s.conf 
sysctl --system

# 以上可以全部复制粘贴直接运行,但是主机名配置需要重新修改

安装docker[ALL]

#源添加
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
#安装docker-ce
yum install  docker-ce -y
# 安装指定版版本 
yum -y install docker-ce-18.09.9-3.el7


###############


# 24之后的版本默认支持containerd
containerd config default > /etc/containerd/config.toml
sed -i 's#registry.k8s.io/pause:3.6#registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6#g' /etc/containerd/config.toml
sed -i 's#SystemdCgroup = false#SystemdCgroup = true#g' /etc/containerd/config.toml





#也可以查看版本安装
#yum list docker-ce --showduplicates | sort -r

#启动docker
systemctl start docker

systemctl enable containerd --now

docker镜像加速&更换镜像位置[ALL]

#第一个是修改默认镜像仓库、
#第二个是更改 docker cgroup的驱动器 改为system
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
   "registry-mirrors": ["https://docker.m.daocloud.io"],
   "exec-opts": ["native.cgroupdriver=systemd"]
 
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

K8S yum源[ALL]

cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

安装kubadmin 和kublete[ALL]

yum install -y kubelet-1.17.0 kubeadm-1.17.0 kubectl-1.17.0
systemctl enable kubelet

master部署[master]

kubeadm init \
  --apiserver-advertise-address=210.47.47.11 \
  --image-repository registry.aliyuncs.com/google_containers \
  --kubernetes-version v1.18.0 \
  --service-cidr=10.1.0.0/16 \
  --pod-network-cidr=10.244.0.0/16

##如下为结果
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:

kubeadm join 192.168.26.134:6443 --token h8ppvi.m3slvdd04yfi69l0 \
    --discovery-token-ca-cert-hash sha256:578d4ccd2514ba5c463f4bec700a70d40efda104019ce57f6e9683cd9ccd85b1

### 最新
kubeadm init   --apiserver-advertise-address=192.168.204.133   --image-repository registry.aliyuncs.com/google_containers   --kubernetes-version v1.29.9   --service-cidr=10.1.0.0/16 

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

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

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:

kubeadm join 192.168.204.133:6443 --token bzvofy.ybhe06r9z2dic4z1 \
        --discovery-token-ca-cert-hash sha256:51a5759b51c2f48d892be6434d03c25e2e054db9f7573e78ba5fb0de84d25542

配置 kubctl [master]

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

查看集群和node状态并处理问题

[root@k8smaster1 ~]# kubectl get cs
NAME                 STATUS    MESSAGE             ERROR
scheduler            Healthy   ok
controller-manager   Healthy   ok
etcd-0               Healthy   {"health":"true"}
[root@k8smaster1 ~]# kubectl get nodes
NAME         STATUS     ROLES    AGE     VERSION
k8smaster1   NotReady   master   5m46s   v1.17.0

#kubctl get nodes 一直是noready 
看/var/log/messages 或者journalctl -f -u kubelet
Jan 26 21:54:52 k8smaster1 kubelet[43973]: E0126 21:54:52.699858   43973 kubelet.go:2183] Container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
Jan 26 21:54:56 k8smaster1 kubelet[43973]: W0126 21:54:56.735289   43973 cni.go:237] Unable to update cni config: no networks found in /etc/cni/net.d
是因为flannel  没装导致,安装flannel 过程比较慢关注flannel的pod状态
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

从机执行[]

kubeadm join 210.47.47.11:6443 --token hl3fx2.dan7m88q0um4z2vi     --discovery-token-ca-cert-hash sha256:08d4139e4a13dfbca62dfac7aca88a80ad96bc464e718324bd4eea2566fee7c4

第二次安装2409

补充1 内核升级

内核升级大版本

补充2 containerd相关配置

containerd 相关配置

补充3 registry 国内相关

#docker修改
/etc/docker/daemon.json 添加
{
  "registry-mirrors": ["https://docker.m.daocloud.io"],
  "exec-opts": ["native.cgroupdriver=systemd"]
  "ipv6": false,
  "fixed-cidr-v6": ""
}

# containerd 修改 ,k8s默认走这的registry 不走docker 的
sed -i 's#registry.k8s.io/pause:3.6#registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6#g' /etc/containerd/config.toml

    [plugins."io.containerd.grpc.v1.cri".registry]
      [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
        [plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
          endpoint = ["https://https://docker.m.daocloud.io"]
        [plugins."io.containerd.grpc.v1.cri".registry.mirrors."k8s.gcr.io"]
          endpoint = ["https://registry.aliyuncs.com/k8sxio"]
        [plugins."io.containerd.grpc.v1.cri".registry.mirrors."gcr.io"]
          endpoint = ["xxx"]

daocloud
国内其他registry
修改containerd registry

补充4 system管理cgroup

k8s 配置Cgroup驱动

##kubelet
# 查看当前kubelet使用哪种方式驱动 cgroup
kubectl get cm kubelet-config -n kube-system -oyaml |grep -i cgroup
#修改 cgroupDriver: systemd
kubectl edit cm kubelet-config -n kube-system

## containerd
sed -i 's#systemdcgroup = false#systemdcgroup = true#g' /etc/containerd/config.toml
systemctl restartd containerd 


##############
#containerd 重启之后 docker 也需要重启因为之前的监听文件的协议变了,与下面问题有关
docker 报错如下
Failed to get event" error="rpc error: code = Unavailable desc = error reading from server: EOF" module=libcontainerd namespace=moby


#### 这里有个问题 目前我的电脑是默认的
如果 containerd 改为 systemdcgroup = true
ep 17 02:24:45 tam3 kubelet: E0917 14:24:45.592732   12366 run.go:74] "command failed" err="failed to run Kubelet: validate service connection: validate CRI v1 runtime API for endpoint \"unix:///var/run/containerd/containerd.sock\": rpc error: code = Unimplemented desc = unknown service runtime.v1.RuntimeService"
Sep 17 02:24:45 tam3 systemd: kubelet.service: main process exited, code=exited, status=1/FAILURE
###报错 感觉是  system 管理 containerd 的 cgroup runtime.v1 可能会变成v2 就不行了只能改回去 之后再研究

## docker 
#查看 
docker info | grep  Cgroup
-- Cgroup Driver: cgroupfs 
#修改
/etc/docker/daemon.json 添加
{
  "registry-mirrors": ["https://82m9ar63.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
}
systemctl restart docker

快照创建机器后操作

1、OS相关

# 修改ip及主机名
sed 's#192.168.204.131#192.168.204.130#g' /etc/sysconfig/network-scripts/ifcfg-ens33
systemctl restart network
hostname set-hostname tam0
#修改集群主机hosts
echo "192.168.204.130 tam0" >> /etc/hosts
echo "192.168.204.131 tam1" >> /etc/hosts
echo "192.168.204.134 tam4" >> /etc/hosts
scp /etc/hosts tam0:/etc/hosts
scp /etc/hosts tam4:/etc/hosts
#免密(客户端执行,生成公钥匙,分发到目的服务器)
ssh-keygen -t rsa
ssh-copy-id 192.168.204.130
ssh-copy-id 192.168.204.134
ssh-copy-id 192.168.204.131
# 分发命令
编辑 all.sh
for i in 0 1 4 ; do ssh tam$i -C "hostname && $*   " ;done
#修改时区
timedatectl set-timezone Asia/Shanghai
#修改dns
echo "nameserver 223.5.5.5" > /etc/resolv.conf 
echo "nameserver 223.6.6.6" >> /etc/resolv.conf 
sleep 10
ping baidu.com -c2 
# 关闭防火墙
systemctl disable firewalld --now
systemctl status firewalld
# 关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config 
setenforce 0
# 关闭swap
swapoff -a
#或将命令加入开机启动
echo "swapoff -a" >>/etc/profile
#时间同步配置
yum install -y ntpdate
ntpdate ntp.aliyun.com
#开启转发
echo -e "net.bridge.bridge-nf-call-iptables = 1 \nnet.ipv4.ip_forward = 1" > /etc/sysctl.d/k8s.conf 
sysctl --system
#升级内核 见补充1
init 6重启后 
uname -r 检查

2、容器基础相关

https://www.cnblogs.com/caixiaozi/p/18154003


########docker
curl  https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo
#安装docker-ce
yum install  docker-ce -y
#也可以查看版本安装
yum list docker-ce --showduplicates | sort -r


#第一个是修改默认镜像仓库、
#第二个是更改 docker cgroup的驱动器 改为system
 mkdir -p /etc/docker
echo -e '{\n   "registry-mirrors": ["https://docker.m.daocloud.io"],\n   "exec-opts": ["native.cgroupdriver=systemd"]\n  }' >>/etc/docker/daemon.json 

sudo systemctl daemon-reload
sudo systemctl restart docker

###############24之后的版本默认支持containerd
containerd config default > /etc/containerd/config.toml
sed -i 's#registry.k8s.io/pause:3.6#registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6#g' /etc/containerd/config.toml
sed -i 's#systemd_cgroup = false#systemd_cgroup = true#g' /etc/containerd/config.toml
grep  systemd_cgroup /etc/containerd/config.toml
systemctl enable containerd --now
systemctl enable docker --now
#启动docker 默认会自动启动containerd

3、K8s

###yum安装 kubelet kubeadm kubectl
cat <<EOF | tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.29/rpm/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.29/rpm/repodata/repomd.xml.key
EOF

yum install -y kubelet kubeadm kubectl
systemctl enable kubelet --now


### kubeadmin初始化k8s amster
 kubeadm init --apiserver-advertise-address=192.168.204.130 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.29.9 --service-cidr=10.96.0.0/12  --pod-network-cidr=10.244.0.0/16

### 初始化结果
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

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

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:

kubeadm join 192.168.204.130:6443 --token n2gv0a.74xu0uj39do2zghu \
        --discovery-token-ca-cert-hash sha256:054b10e8d92c9919c38a208a4bba62f5f78e0a2c23e7acca91ef3a3944ad5bfe 
### cni
wget https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/calico.yaml
kubectl create -f calico.yaml
watch kubectl get pods -A
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,639评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,277评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,221评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,474评论 1 283
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,570评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,816评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,957评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,718评论 0 266
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,176评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,511评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,646评论 1 340
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,322评论 4 330
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,934评论 3 313
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,755评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,987评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,358评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,514评论 2 348

推荐阅读更多精彩内容