Amazon Linux2使用kubeadm部署安装K8S集群

这篇具有很好参考价值的文章主要介绍了Amazon Linux2使用kubeadm部署安装K8S集群。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

环境信息

在AWS上启动3台Amazon Linux2的服务器,服务器配置为2vcpu 和2GB内存

部署K8S集群

1. 修改主机名(可选步骤)

sudo hostnamectl set-hostname master

2.导入k8s的yum仓库密钥

sudo rpm --import https://packages.cloud.google.com/yum/doc/yum-key.gpg

3. 配置kubernetes源

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
       https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

4. 部署安装kubeadm、kubectl、docker,并且启动docker

sudo yum install -y kubeadm kubectl docker
sudo systemctl enable docker --now
sudo systemctl status docker

5. 在master节点上执行初始化

kubeadm init --apiserver-advertise-address=172.31.1.86 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16

具体初始化过程如下

[init] Using Kubernetes version: v1.27.1
[preflight] Running pre-flight checks
        [WARNING FileExisting-tc]: tc not found in system path
        [WARNING Hostname]: hostname "master" could not be reached
        [WARNING Hostname]: hostname "master": lookup master on 172.31.0.2:53: no such host
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
W0423 06:37:02.471385   10481 images.go:80] could not find officially supported version of etcd for Kubernetes v1.27.1, falling back to the nearest etcd version (3.5.7-0)
W0423 06:37:10.618968   10481 checks.go:835] detected that the sandbox image "registry.k8s.io/pause:3.6" of the container runtime is inconsistent with that used by kubeadm. It is recommended that using "registry.k8s.io/pause:3.9" as the CRI sandbox image.
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local master] and IPs [10.1.0.1 172.31.1.86]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [localhost master] and IPs [172.31.1.86 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [localhost master] and IPs [172.31.1.86 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
W0423 06:37:19.434528   10481 images.go:80] could not find officially supported version of etcd for Kubernetes v1.27.1, falling back to the nearest etcd version (3.5.7-0)
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[apiclient] All control plane components are healthy after 8.501748 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config" in namespace kube-system with the configuration for the kubelets in the cluster
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node master as control-plane by adding the labels: [node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node master as control-plane by adding the taints [node-role.kubernetes.io/control-plane:NoSchedule]
[bootstrap-token] Using token: 51vh1y.t1aswu9squ1fbstb
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to get nodes
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] Configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] Configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy

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 172.31.1.86:6443 --token 51vh1y.t1aswu9squ1fbstb \
        --discovery-token-ca-cert-hash sha256:b090433d2121dd5cfba2e28d9da1219c2c38debfa15550e866de35f42b143600
 

6. 根据提示创建kubeconfig配置文件

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

7. 验证集群是否初始化正常

[ec2-user@master ~]$ kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.1.0.1     <none>        443/TCP   56s
[ec2-user@master ~]$

8. 查看集群节点

$ kubectl get nodes
NAME     STATUS     ROLES           AGE     VERSION
master   NotReady   control-plane   9m51s   v1.27.1

9. 在master上下载flannel网络配置文件

curl -O https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

[ec2-user@master ~]$ kubectl apply -f kube-flannel.yml
namespace/kube-flannel created
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.apps/kube-flannel-ds created
[ec2-user@master ~]$

10. 部署好网络插件之后此时再次查看节点可以看到状态变成了ready

[ec2-user@master ~]$ kubectl get nodes
NAME     STATUS   ROLES           AGE   VERSION
master   Ready    control-plane   16m   v1.27.1
[ec2-user@master ~]$

11. 将其他两个节点加入到集群中去

sudo kubeadm join 172.31.1.86:6443 --token 51vh1y.t1aswu9squ1fbstb --discovery-token-ca-cert-hash sha256:b090433d2121dd5cfba2e28d9da1219c2c38debfa15550e866de35f42b143600

具体执行过程如下

[ec2-user@node1 ~]$ sudo kubeadm join 172.31.1.86:6443 --token t9v92n.phs28c3pxmzb0ftc --discovery-token-ca-cert-hash sha256:b090433d2121dd5cfba2e28d9da1219c2c38debfa15550e866de35f42b143600
[preflight] Running pre-flight checks
        [WARNING FileExisting-tc]: tc not found in system path
        [WARNING Hostname]: hostname "node1" could not be reached
        [WARNING Hostname]: hostname "node1": lookup node1 on 172.31.0.2:53: no such host
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

[ec2-user@node1 ~]$ kubectl get nodes
NAME     STATUS   ROLES           AGE   VERSION
master   Ready    control-plane   51m   v1.27.1
node1    Ready    <none>          6s    v1.27.1
[ec2-user@node1 ~]$

kubectl常用命令

1. 查看节点

kubectl get nodes -owide

2. 查看pod信息

[ec2-user@master ~]$ kubectl get pods -n kube-system
NAME                             READY   STATUS    RESTARTS   AGE
coredns-5d78c9869d-68pw4         1/1     Running   0          6m32s
coredns-5d78c9869d-hds64         1/1     Running   0          5m31s
etcd-master                      1/1     Running   0          55m
kube-apiserver-master            1/1     Running   0          55m
kube-controller-manager-master   1/1     Running   0          55m
kube-proxy-kxhgc                 1/1     Running   0          4m9s
kube-proxy-rtzqt                 1/1     Running   0          54m
kube-scheduler-master            1/1     Running   0          55m
[ec2-user@master ~]$

3. 查看namespace信息

[ec2-user@master ~]$ kubectl get ns
NAME              STATUS   AGE
default           Active   55m
kube-flannel      Active   39m
kube-node-lease   Active   55m
kube-public       Active   55m
kube-system       Active   55m
[ec2-user@master ~]$

4. 查看deployment

[ec2-user@master ~]$ kubectl get deploy -A
NAMESPACE     NAME      READY   UP-TO-DATE   AVAILABLE   AGE
kube-system   coredns   2/2     2            2           56m
[ec2-user@master ~]$

kubeadm常用命令

1. 查看加入集群使用的命令

 kubeadm token create --print-join-command

2. 将某个节点从集群中做下线

  •   在要下线的节点上执行如下命令
sudo kubeadm reset
  • 在集群中的其他节点上运行以下命令,将移除的节点从集群中删除
kubectl delete node <node-name>

 

实现kubectl命令自动补齐功能

常用的插件是bash-completion和zsh-completion

1. 部署安装bash-completion

sudo yum install -y bash-completion

2. 将kubectl自动补齐脚本拷贝到bash_completion.d目录下

sudo kubectl completion bash > /etc/bash_completion.d/kubectl

3. 重启bash shell

exec bash

或者执行如下命令

source /etc/bash_completion.d/kubectl

之后即可使用table键继续命令的补齐文章来源地址https://www.toymoban.com/news/detail-459468.html

到了这里,关于Amazon Linux2使用kubeadm部署安装K8S集群的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • K8S1.23.6版本详细安装教程以及错误解决方案(包括前置环境,使用部署工具kubeadm来引导集群)

    一台兼容的 Linux 主机。Kubernetes 项目为基于 Debian 和 Red Hat 的 Linux 发行版以及一些不提供包管理器的发行版提供通用的指令。 每台机器 2 GB 或更多的 RAM(如果少于这个数字将会影响你应用的运行内存)。 CPU 2 核心及以上。 集群中的所有机器的网络彼此均能相互连接(公网和

    2024年03月14日
    浏览(32)
  • 使用kubeadm方式快速部署一个K8S集群

    目录 一、环境准备 二、环境初始化  三、在所有主机上安装相关软件 1、安装docker 2、配置k8s的yum源 3、安装kubelet、kubeadm、kubectl 四、部署Kubernetes Master 五、加入Kubernets Node 六、部署CNI网络插件 七、测试k8s集群 我的是CentOS7系统,然后准备三台虚拟主机 一台master,和两台no

    2024年02月11日
    浏览(42)
  • Kubernetes技术--使用kubeadm快速部署一个K8s集群

    这里我们配置一个 单master集群 。( 一个Master节点,多个Node节点 ) 1.硬件环境准备 一台或多台机器,操作系统 CentOS7.x-86_x64 。这里我们使用安装了CentOS7的三台虚拟机 硬件配置 : 2GB或更多RAM , 2个CPU或更多CPU , 硬盘30GB或更多 2.主机名称和IP地址规划 3. 初始化准备工作 (1).关

    2024年02月10日
    浏览(38)
  • CentOS7使用kubeadm部署k8s-1.28集群

    参考资料:生产环境 记录使用CentOS7.9进行k8s-1.28版本部署,运行时环境使用containerd,网络插件使用calic,集群搭建完成后。搭建NFS共享存储环境,测试运行pod并挂载使用持久卷。 主机名 **IP地址 ** 角色 基础组件 el7-linux-node-01 192.168.240.11 k8s-master kubeadm,kubelet,kubectl,containerd,nf

    2024年04月26日
    浏览(37)
  • Ubuntu 使用Kubeadm 离线安装k8s

    K8S离线部署的方案 离线包,自己可以跟着下面步骤自己下载。 https://download.csdn.net/download/u010952056/86748944 万字长文详解 PaaS toB 场景下 K8s 离线部署方案 Item Language 离线部署支持情况 kops Golang 不支持 kubespray Ansible 支持,需自行构建安装包 kubeasz Ansible 支持,需自行构建安装包

    2024年02月05日
    浏览(40)
  • 使用kubeadm安装和设置Kubernetes(k8s)

    kubeadm是官方社区推出的一个用于快速部署kubernetes集群的工具。 这个工具能通过两条指令完成一个kubernetes集群的部署: 使用kubeadm方式搭建K8s集群主要分为以下几步 准备三台虚拟机,同时安装操作系统CentOS 7.x 对三个安装之后的操作系统进行初始化操作 在三个节点安装 dock

    2024年02月12日
    浏览(34)
  • k8s证书更新,kubeadm安装的K8S证书过期后无法使用后证书更新方法

    k8s安装一年后证书显示过期。证书未自动续期。 以下操作需到所有master节点操作 一般情况下,k8s创建的集群节点上的/usr/bin/文件夹下会存在kubeadm二进制文件,如果发现master节点上没有kubeadm,可以从官方下载对应的版本并且安装。

    2024年02月14日
    浏览(37)
  • CentOS 7/8使用kubeadm部署kubernets(k8s)集群【附阿里云实验室】

    好消息好消息,阿里云全线降价,大量服务提供免费甚至永久的试用,赶紧来薅大厂羊毛吧,坐电梯即可直达! 送福利!阿里云热门产品免费领(含ECS),点击进入 :https://click.aliyun.com/m/1000370359/ 送福利!阿里云热门产品免费领(含ECS),点击进入 :https://click.aliyun.com/m/

    2023年04月22日
    浏览(33)
  • 麒麟v10使用kubeadm安装k8s1.26

    苦于目前下载不到现成el8的kubelet/kubeadm/kubectl,就算有,以后如果在arm架构上安装,又要寻找新的包,通过摸索,找到了源码构建方法。无论是arm架构还是amd架构,都是可以使用该办法进行安装。 服务器IP 主机名 用途 部署说明 192.168.1.3 kmaster1 主节点1 kubelet/kubeadm/kubectl/cont

    2024年02月02日
    浏览(42)
  • Kubeadm部署K8s

    集群规划: Master节点规划: Node节点规划: 安装要求 此实验机器规划如下: 在各节点执行—修改主机名 在各节点执行—修改hosts文件 在各节点执行—修改DNS 在各节点执行—设置个性主机名: 在各节点执行—关闭CentOS7自带的防火墙服务 在各节点执行—关闭selinux 在各节点执行—

    2024年03月11日
    浏览(32)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包