Kubernetes指南從零開(kāi)始搭建集群

Kubernetes指南: 從零開(kāi)始搭建集群

成都創(chuàng)新互聯(lián)主要從事成都網(wǎng)站建設(shè)、做網(wǎng)站、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)玉泉,十余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專(zhuān)業(yè),歡迎來(lái)電咨詢(xún)建站服務(wù):13518219792

在云計(jì)算時(shí)代,容器化已經(jīng)成為了一種廣泛使用的技術(shù),Kubernetes是其中的佼佼者,其作為一個(gè)容器編排平臺(tái),在管理上的優(yōu)勢(shì)及其高可用性、易擴(kuò)展性深受企業(yè)和開(kāi)發(fā)者的喜愛(ài)。在本文章中,我們將從零開(kāi)始搭建Kubernetes集群,并解釋其中的技術(shù)知識(shí)點(diǎn)。

1. 環(huán)境準(zhǔn)備

在開(kāi)始之前,需要先確定好環(huán)境,Kubernetes分為Master節(jié)點(diǎn)和Worker節(jié)點(diǎn),其中Master節(jié)點(diǎn)需要至少2個(gè),Worker節(jié)點(diǎn)至少1個(gè),硬件環(huán)境和軟件環(huán)境需要滿(mǎn)足一定的要求。硬件環(huán)境建議:

- Master節(jié)點(diǎn):CPU 2核,內(nèi)存 2GB,硬盤(pán) 40GB以上

- Worker節(jié)點(diǎn):CPU 4核,內(nèi)存 4GB,硬盤(pán) 40GB以上

軟件環(huán)境建議:

- 操作系統(tǒng):CentOS7.4以上

- Docker:18.09.0以上

- Kubeadm:1.20.1及以上

2. 安裝Docker

在CentOS系統(tǒng)下,我們可以執(zhí)行下方腳本安裝Docker:

`bash

$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2

$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

$ sudo yum install -y docker-ce-18.09.0 docker-ce-cli-18.09.0 containerd.io

$ sudo systemctl start docker

$ sudo systemctl enable docker

3. 安裝Kubeadm我們可以執(zhí)行如下腳本安裝Kubeadm:`bash$ sudo vi /etc/sysctl.d/k8s.conf # 寫(xiě)入如下內(nèi)容net.bridge.bridge-nf-call-ip6tables = 1net.bridge.bridge-nf-call-iptables = 1$ sudo sysctl --system$ sudo setenforce 0$ sudo sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config $ sudo vi /etc/yum.repos.d/kubernetes.repo# 寫(xiě)入如下內(nèi)容[kubernetes]name=Kubernetesbaseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/enabled=1gpgcheck=0repo_gpgcheck=0gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg$ sudo yum install -y kubelet-1.20.1 kubeadm-1.20.1 kubectl-1.20.1 --disableexcludes=kubernetes$ sudo systemctl enable kubelet$ sudo systemctl start kubelet

4. 搭建Master節(jié)點(diǎn)

在搭建Master節(jié)點(diǎn)時(shí),我們需要先確定好IP地址,并編輯好如下配置文件:

`yaml

apiVersion: kubeadm.k8s.io/v1beta2

kind: ClusterConfiguration

kubernetesVersion: stable

apiServer:

certSANs:

- "{{ Master節(jié)點(diǎn)IP地址 }}"

controlPlaneEndpoint: "{{ Master節(jié)點(diǎn)IP地址 }}:6443"

extraArgs:

audit-log-path: /var/log/kubernetes/audit.log

audit-log-maxage: "30"

audit-log-maxbackup: "3"

audit-log-maxsize: "100"

authorization-mode: Node,RBAC

enable-admission-plugins: NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,ResourceQuota

runtime-config: api/all=true

service-node-port-range: 30000-32767

controllerManager:

extraArgs:

node-cidr-mask-size: "24"

node-monitor-grace-period: "30s"

pod-eviction-timeout: "2m"

use-service-account-credentials: "true"

networking:

dnsDomain: cluster.local

podSubnet: "10.244.0.0/16"

serviceSubnet: "10.96.0.0/12"

然后,我們?cè)贛aster節(jié)點(diǎn)上執(zhí)行如下腳本:`bash$ sudo kubeadm init --config kubeadm-config.yaml

在執(zhí)行完成后,我們可以看到如下輸出:

`bash

[init] Using Kubernetes version: v1.20.0

[preflight] Running pre-flight checks

[WARNING FileExisting-crictl]: crictl not found in system path

[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'

[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

[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 [master-1 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.1.120]

[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] and IPs [192.168.1.120 127.0.0.1 ::1]

[certs] Generating "etcd/peer" certificate and key

[certs] etcd/peer serving cert is signed for DNS names [localhost] and IPs [192.168.1.120 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

[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

[kubelet-check] Initial timeout of 40s passed.

[apiclient] All control plane components are healthy after 80.001069 seconds

[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace

[kubelet] Creating a ConfigMap "kubelet-config-1.20" in namespace kube-system with the configuration for the kubelets in the cluster

[kubelet-start] Restarting the kubelet to use the new kubelet configuration

[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

[csr-approver] CSR approval is disabled. Nodes that match this CSR will be not be permitted to join the cluster. Passing --apiserver-advertise-address=0.0.0.0 may allow unauthorized nodes to join the cluster.

[bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster

[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 {{ Master節(jié)點(diǎn)IP地址 }}:6443 --token {{ Token }} \

--discovery-token-ca-cert-hash sha256:{{ CA證書(shū)哈希值 }}

在執(zhí)行完成后,我們需要執(zhí)行如下腳本,讓普通用戶(hù)也擁有使用Kubernetes的權(quán)限:`bash$ mkdir -p $HOME/.kube$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config$ sudo chown $(id -u):$(id -g) $HOME/.kube/config

5. 搭建Worker節(jié)點(diǎn)

在搭建Worker節(jié)點(diǎn)時(shí),我們需要使用之前Master節(jié)點(diǎn)輸出的join命令,并將其執(zhí)行在Worker節(jié)點(diǎn)上,如下:

`bash

$ sudo kubeadm join {{ Master節(jié)點(diǎn)IP地址 }}:6443 --token {{ Token }} \

--discovery-token-ca-cert-hash sha256:{{ CA證書(shū)哈希值 }}

執(zhí)行成功后,在Master節(jié)點(diǎn)上執(zhí)行如下腳本:`bash$ kubectl get nodes

如果輸出了剛剛加入的Worker節(jié)點(diǎn)信息,說(shuō)明Worker節(jié)點(diǎn)已經(jīng)成功加入到了集群中。

至此,我們已經(jīng)成功搭建了一個(gè)Kubernetes集群,并且已經(jīng)加入了一個(gè)Worker節(jié)點(diǎn)。在實(shí)際生產(chǎn)環(huán)境中,我們還需要進(jìn)行更多的配置和優(yōu)化,例如網(wǎng)絡(luò)、存儲(chǔ)、高可用性等方面,這將在后續(xù)的文章中進(jìn)行探討。

網(wǎng)頁(yè)標(biāo)題:Kubernetes指南從零開(kāi)始搭建集群
標(biāo)題網(wǎng)址:http://www.muchs.cn/article18/dgphegp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、網(wǎng)站改版標(biāo)簽優(yōu)化、微信公眾號(hào)、商城網(wǎng)站、網(wǎng)站維護(hù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

微信小程序開(kāi)發(fā)