【云原生】KubeKey一键部署Kubernetes

作者:Administrator 发布时间: 2025-11-09 阅读量:4 评论数:0

资源列表

操作系统

配置

主机名

IP

所需软件

CentOS 7.9

2C4G

kubekey

192.168.93.101

kk kubectl

基础环境

  • 关闭防火墙

systemctl stop firewalld
systemctl disable firewalld
  • 关闭内核安全机制

setenforce 0
sed -i "s/^SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config
  • 修改主机名

hostnamectl set-hostname kubekey
  • hosts解析

echo "192.168.93.101 kubekey" >> /etc/hosts
  • SSH免密

ssh-keygen  # 一路回车
​
ssh-copy-id root@192.168.93.101  # 给自己做免密

一、环境准备

# 创建所需目录
[root@kubekey ~]# cd /home/
[root@kubekey home]# mkdir kubekey
[root@kubekey home]# cd kubekey/
​
​
# 安装依赖组件
[root@kubekey home]# yum install -y ebtables socat ipset conntrack

二、使用KubeKey一键安装

  • KubeKey是一个一键安装Kubernetes所有组件的工具。

2.1、下载kubekey

[root@kubekey kubekey]# yum -y install wget
​
​
# 设置此环境变量之后,kubekey将会从国内拉取k8s所需镜像
[root@kubekey kubekey]# export KKZONE=cn
​
​
# 下载kk(kubekey)
[root@kubekey kubekey]# curl -sfL https://get-kk.kubesphere.io | sh -
[root@kubekey kubekey]# chmod +x kk

2.2、生成配置文件

[root@kubekey kubekey]# ./kk create config
Generate KubeKey config file successfully

2.3、修改配置文件

[root@kubekey kubekey]# cat config-sample.yaml 

apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
  name: sample
spec:
  hosts:
  - {name: kubekey, address: 192.168.93.101, internalAddress: 192.168.93.101}  # 修改此处
  # - {name: node2, address: 172.16.0.3, internalAddress: 172.16.0.3, user: ubuntu, password: "Qcloud@123"}
  roleGroups:
    etcd:
    - kubekey
    control-plane: 
    - kubekey
    worker:
    - kubekey
    # - node2
  controlPlaneEndpoint:
    ## Internal loadbalancer for apiservers 
    # internalLoadbalancer: haproxy

    domain: lb.kubesphere.local
    address: ""
    port: 6443
  kubernetes:
    version: v1.23.17  # k8s 版本
    clusterName: cluster.local
    autoRenewCerts: true
    containerManager: docker
  etcd:
    type: kubekey
  network:
    plugin: calico
    kubePodsCIDR: 10.233.64.0/18
    kubeServiceCIDR: 10.233.0.0/18
    ## multus support. https://github.com/k8snetworkplumbingwg/multus-cni
    multusCNI:
      enabled: false
  registry:
    privateRegistry: ""
    namespaceOverride: ""
    registryMirrors: []
    insecureRegistries: []
  addons: []

2.4、执行安装

# 通过指定配置文件来创建集群
[root@kubekey kubekey]# ./kk create cluster -f config-sample.yaml


 _   __      _          _   __           
| | / /     | |        | | / /           
| |/ / _   _| |__   ___| |/ /  ___ _   _ 
|    \| | | | '_ \ / _ \    \ / _ \ | | |
| |\  \ |_| | |_) |  __/ |\  \  __/ |_| |
\_| \_/\__,_|_.__/ \___\_| \_/\___|\__, |
                                    __/ |
                                   |___/

19:47:58 CST [GreetingsModule] Greetings
19:47:58 CST message: [kubekey]
Greetings, KubeKey!
19:47:58 CST success: [kubekey]
19:47:58 CST [NodePreCheckModule] A pre-check on nodes
19:47:59 CST success: [kubekey]
19:47:59 CST [ConfirmModule] Display confirmation form
+---------+------+------+---------+----------+-------+-------+---------+-----------+--------+--------+------------+------------+-------------+------------------+--------------+
| name    | sudo | curl | openssl | ebtables | socat | ipset | ipvsadm | conntrack | chrony | docker | containerd | nfs client | ceph client | glusterfs client | time         |
+---------+------+------+---------+----------+-------+-------+---------+-----------+--------+--------+------------+------------+-------------+------------------+--------------+
| kubekey | y    | y    | y       | y        | y     | y     |         | y         | y      |        | y          |            |             |                  | CST 19:47:59 |
+---------+------+------+---------+----------+-------+-------+---------+-----------+--------+--------+------------+------------+-------------+------------------+--------------+

This is a simple check of your environment.
Before installation, ensure that your machines meet all requirements specified at
https://github.com/kubesphere/kubekey#requirements-and-recommendations

Install k8s with default version:  v1.23.17

Continue this installation? [yes/no]: yes   # 输入 yes 等待安装完成即可

2.5、安装kubectl

[root@kubekey kubekey]# # curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

2.6、查看所有Pod状态

[root@kubekey kubekey]# kubectl get pod -A
NAMESPACE     NAME                                       READY   STATUS    RESTARTS   AGE
kube-system   calico-kube-controllers-6f996c8485-zkzr7   1/1     Running   0          4m27s
kube-system   calico-node-wqs5f                          1/1     Running   0          4m27s
kube-system   coredns-6d5894bf8b-ddzds                   1/1     Running   0          4m27s
kube-system   coredns-6d5894bf8b-jhng7                   1/1     Running   0          4m27s
kube-system   kube-apiserver-kubekey                     1/1     Running   0          4m42s
kube-system   kube-controller-manager-kubekey            1/1     Running   0          4m43s
kube-system   kube-proxy-s2pj9                           1/1     Running   0          4m27s
kube-system   kube-scheduler-kubekey                     1/1     Running   0          4m43s
kube-system   nodelocaldns-bzdqh                         1/1     Running   0          4m27s


评论