Ubuntu22.04.4安装k8s集群(下)
本文为博主独立完成的原创技术文档,首发于个人博客。
转载须知:
✅ 欢迎分享本文链接至技术群、朋友圈
✅ 个人收藏、学习使用不限
❌ 严禁洗稿、抄袭,或未经授权的商业转载/汇编
📩 如需转载至其他平台,请私信联系博主获取授权
作者:赵俊杰
一.环境描述
Ubuntu系统22.04.4版本2核3G
10.0.0.111 master111
10.0.0.112 worker112
10.0.0.113 worker113

保证机器可以上网:

二.kubeadm部署k8s集群(上)
见上篇文章
三.kubeadm部署k8s集群(下)
注意:安装过的kubeadm、kubectl、kubele包会存放在以下路径:/var/cache/apt/archives/*.deb
如果生产有需求,无法连接网络部署则提前将包拷贝出来(包含依赖)
master111节点执行,kubeadm初始化master节点:
kubeadm init --kubernetes-version=v1.23.17 --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr=10.100.0.0/16 --service-cidr=10.200.0.0/16 --service-dns-domain=zhaojunjiecluster --apiserver-advertise-address=10.0.0.111
# 注意:如果有多块物理网卡时--apiserver-advertise-address,此环境为单块网卡无需配置此选项。
参数:
相关参数说明:
--kubernetes-version:指定K8S master组件的版本号。
--image-repository:指定下载k8s master组件的镜像仓库地址。
--pod-network-cidr:指定Pod的网段地址。
--service-cidr:指定SVC的网段
--service-dns-domain:指定service的域名。若不指定,默认为"cluster.local"。
等待时间略长,因为初始化过程需要拉取镜像,输出结果如下:
root@master111:~# kubeadm init --kubernetes-version=v1.23.17 --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr=10.100.0.0/16 --service-cidr=10.200.0.0/16 --service-dns-domain=zhaojunjiecluster --apiserver-advertise-address=10.0.0.111
[init] Using Kubernetes version: v1.23.17
[preflight] Running pre-flight checks
[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'
[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.zhaojunjiecluster master111] and IPs [10.200.0.1 10.0.0.111]
[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 master111] and IPs [10.0.0.111 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [localhost master111] and IPs [10.0.0.111 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"
[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.005438 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.23" in namespace kube-system with the configuration for the kubelets in the cluster
NOTE: The "kubelet-config-1.23" naming of the kubelet ConfigMap is deprecated. Once the UnversionedKubeletConfigMap feature gate graduates to Beta the default name will become just "kubelet-config". Kubeadm upgrade will handle this transition transparently.
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node master111 as control-plane by adding the labels: [node-role.kubernetes.io/master(deprecated) node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node master111 as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: 908qmy.vgyxtah6epb46dx0
[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:
#worer初始化命令
kubeadm join 10.0.0.111:6443 --token 908qmy.vgyxtah6epb46dx0 \
--discovery-token-ca-cert-hash sha256:1ca3ea46e9355a8fd6d097db5d45b47440470e23677f4ae5caacae05369e1a49
root@master111:~#
查看镜像列表:
root@master111:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.aliyuncs.com/google_containers/kube-apiserver v1.23.17 62bc5d8258d6 3 years ago 130MB
registry.aliyuncs.com/google_containers/kube-proxy v1.23.17 f21c8d21558c 3 years ago 111MB
registry.aliyuncs.com/google_containers/kube-controller-manager v1.23.17 1dab4fc7b6e0 3 years ago 120MB
registry.aliyuncs.com/google_containers/kube-scheduler v1.23.17 bc6794cb54ac 3 years ago 51.9MB
registry.aliyuncs.com/google_containers/etcd 3.5.6-0 fce326961ae2 3 years ago 299MB
registry.aliyuncs.com/google_containers/coredns v1.8.6 a4ca41631cc7 4 years ago 46.8MB
registry.aliyuncs.com/google_containers/pause 3.6 6270bb605e12 5 years ago 683kB
root@master111:~#

woker112和worker113执行,kubeadm部署worker节点:
kubeadm join 10.0.0.111:6443 --token 908qmy.vgyxtah6epb46dx0 \
--discovery-token-ca-cert-hash sha256:1ca3ea46e9355a8fd6d097db5d45b47440470e23677f4ae5caacae05369e1a49
准备集群配置文件:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
worker节点镜像查看:
root@worker112:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.aliyuncs.com/google_containers/kube-proxy v1.23.17 f21c8d21558c 3 years ago 111MB
registry.aliyuncs.com/google_containers/pause 3.6 6270bb605e12 5 years ago 683kB
root@worker112:~#
root@worker113:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.aliyuncs.com/google_containers/kube-proxy v1.23.17 f21c8d21558c 3 years ago 111MB
registry.aliyuncs.com/google_containers/pause 3.6 6270bb605e12 5 years ago 683kB
root@worker113:~#

master节点检查集群的worker节点列表:
root@master111:~# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master111 NotReady control-plane,master 5m38s v1.23.17
worker112 NotReady <none> 2m5s v1.23.17
worker113 NotReady <none> 2m5s v1.23.17
root@master111:~#
部署Flannel的资源清单并修改Pod网段:
参考官网:
https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
下载并修改:
root@master111:~# grep -A5 net-conf.json kube-flannel.yml
net-conf.json: |
{
"Network": "10.100.0.0/16",
"EnableNFTables": false,
"Backend": {
"Type": "vxlan"
root@master111:~#
root@master111:~# sed -i 's#ghcr.io/flannel-io#registry.aliyuncs.com/flannel_io#g' kube-flannel.yml
root@master111:~#
root@master111:~# grep image kube-flannel.yml
image: registry.aliyuncs.com/flannel_io/flannel:v0.28.9
image: registry.aliyuncs.com/flannel_io/flannel-cni-plugin:v1.9.1-flannel3
image: registry.aliyuncs.com/flannel_io/flannel:v0.28.9
root@master111:~#
部署完成!!!
当你凝视深渊的时候,深渊也在凝视你。当你看到遥不可及的东西时,ta也在看向你,加油!
本文来自博客园,作者:超级喜欢下雨天,转载请注明原文链接:https://www.cnblogs.com/zhao-junjie/p/22895009

浙公网安备 33010602011771号