欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

kubeadm部署k8s集群全過程

 更新時間:2025年01月08日 10:09:09   作者:夜夜流光相皎潔_小寧  
本文詳細描述了如何在VMware虛擬機上基于CentOS8操作系統(tǒng)搭建Kubernetes集群,包括環(huán)境準(zhǔn)備、Docker安裝、Kubernetes組件安裝、網(wǎng)絡(luò)插件配置以及KuboardUI的安裝和訪問

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

本文基于VMware虛擬機,基于CentOS 8操作系統(tǒng)實現(xiàn)。

機器節(jié)點信息

服務(wù)器IP地址
master192.168.31.80
node1192.168.31.8
node2192.168.31.9

更換鏡像地址

sudo sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sudo sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

更換語言環(huán)境

dnf install glibc-langpack-zh.x86_64

echo LANG=zh_CN.UTF-8 > /etc/locale.conf

source /etc/locale.conf

更換時區(qū)

timedatectl list-timezones
timedatectl set-timezone Asia/Shanghai
timedatectl

關(guān)閉防火墻

systemctl stop firewalld
systemctl stop iptables
iptables -F &&  iptables -t nat -F &&  iptables -t mangle -F &&  iptables -X

關(guān)閉selinux

  • 臨時關(guān)閉
setenforce 0
  • 永久關(guān)閉
#vim /etc/selinux/config 然后設(shè)置 SELINUX=disabled 
vim /etc/selinux/config

關(guān)閉交換分區(qū)

swapoff -a
sed -ri  's/.*swap.*/#&/' /etc/fstab

修改主機信息

# 查看當(dāng)前主機名稱
hostname
# 修改主機名稱 master節(jié)點修改成master、node1節(jié)點修改成node1、node2節(jié)點修改成node2
hostnamectl set-hostname master

更新節(jié)點的本地域名IP解析

# 編輯hosts文件,將master、node1、node2節(jié)點ip添加進去,三個節(jié)點都需要添加
vim /etc/hosts

調(diào)整內(nèi)核參數(shù)

cd /etc/sysctl.d/

#更新kubernetes.conf文件信息
cat > kubernetes.conf   << EOF
#開啟網(wǎng)橋模式,可將網(wǎng)橋的流量傳遞給iptables鏈
net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-iptables=1
#關(guān)閉ipv6協(xié)議
net.ipv6.conf.all.disable_ipv6=1
net.ipv4.ip_forward=1
EOF

# 加載參數(shù)

sysctl --system

安裝docker

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

yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 

yum install -y docker-ce docker-ce-cli containerd.io

配置docker

cd /etc/docker/

cat > daemon.json << EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "registry-mirrors" : [
    "https://ot2k4d59.mirror.aliyuncs.com/"
  ]
}
EOF

systemctl daemon-reload

systemctl restart docker.service

systemctl enable docker.service

docker info | grep "Cgroup Driver"

到此,docker安裝成功。

配置k8s源

cd /etc/yum.repos.d/

cat > 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

安裝kubeadm kubelet kubectl

yum install -y kubelet-1.21.3  kubeadm-1.21.3  kubectl-1.21.3

開機自啟kubelet

systemctl enable kubelet.service

systemctl start kubelet

到此,kubeadm、kubelet、kubectl 安裝完成,截至目前為止,以上內(nèi)容,master、node1、node2都需要執(zhí)行。

master節(jié)點部署

初始化kubeadm

# --apiserver-advertise-address 初始化master監(jiān)聽地址,改成自己的master節(jié)點IP地址
# --image-repository 指定aliyun下載源
# --kubernetes-version 指定k8s下載版本
# --service-cidr 設(shè)置集群內(nèi)部網(wǎng)絡(luò)
# --pod-network-cidr 設(shè)置pod的網(wǎng)絡(luò)
# service-cidr和pod-network-cidr最好就用這個,不然后面安裝kube-flannel,就需要修改kube-flannel.yaml的配置
kubeadm init --apiserver-advertise-address=192.168.31.80 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.21.14 --service-cidr=10.96.0.0/12 --pod-network-cidr=10.244.0.0/16


# 進入kubernetes 配置中
cd /etc/kubernetes/manifests

# 26行 --port=0 #注釋掉
vim kube-controller-manager.yaml


#19行  --port=0 #注釋掉
vim kube-scheduler.yaml 

#給node節(jié)點添加標(biāo)簽
kubectl label node node1  node-role.kubernetes.io/node=node1

kubectl label node node2  node-role.kubernetes.io/node=node2

執(zhí)行kubectl管理工具

mkdir -p $HOME/.kube

sudo  cp  -i  /etc/kubernetes/admin.conf  $HOME/.kube/config

sudo  chown  $(id --u):$(id -g)  $HOME/.kube/config

Token制作

# 主要是node1、node2節(jié)點join 進入master節(jié)點需要
kubeadm token create --print-join-command

Node節(jié)點加入集群

# 上一步生成的token,粘貼命令到node1、node2節(jié)點執(zhí)行
kubeadm join 192.168.48.130:6443 --token jgijaq.wpzj5oco3j03u1nb --discovery-token-ca-cert-hash sha256:c7c9a9e411fecb16807ea6bace2ce4a22828f2505167049ab20000c1cb5360b4 
#查看集群節(jié)點信息
kubectl get nodes

我們發(fā)現(xiàn),集群節(jié)點的狀態(tài)都是NotReady狀態(tài),這是因為我們還沒有安裝網(wǎng)絡(luò)插件,下面,我們需要安裝kube-flannel插件

安裝kube-flannel插件(所有節(jié)點都需要)

# 新建kube-flannel.yml
cat > kube-flannel.yml
# 然后去github上面去把kube-flannel.yml內(nèi)容粘貼下來,復(fù)制到本地的kube-flannel.yml文件中,地址:https://github.com/flannel-io/flannel/blob/master/Documentation/kube-flannel.yml

vim kube-flannel.yml
# kube-flannel.yml內(nèi)容,不需要修改,直接可以使用
---
kind: Namespace
apiVersion: v1
metadata:
  name: kube-flannel
  labels:
    k8s-app: flannel
    pod-security.kubernetes.io/enforce: privileged
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  labels:
    k8s-app: flannel
  name: flannel
rules:
- apiGroups:
  - ""
  resources:
  - pods
  verbs:
  - get
- apiGroups:
  - ""
  resources:
  - nodes
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - nodes/status
  verbs:
  - patch
- apiGroups:
  - networking.k8s.io
  resources:
  - clustercidrs
  verbs:
  - list
  - watch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  labels:
    k8s-app: flannel
  name: flannel
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: flannel
subjects:
- kind: ServiceAccount
  name: flannel
  namespace: kube-flannel
---
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    k8s-app: flannel
  name: flannel
  namespace: kube-flannel
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: kube-flannel-cfg
  namespace: kube-flannel
  labels:
    tier: node
    k8s-app: flannel
    app: flannel
data:
  cni-conf.json: |
    {
      "name": "cbr0",
      "cniVersion": "0.3.1",
      "plugins": [
        {
          "type": "flannel",
          "delegate": {
            "hairpinMode": true,
            "isDefaultGateway": true
          }
        },
        {
          "type": "portmap",
          "capabilities": {
            "portMappings": true
          }
        }
      ]
    }
  net-conf.json: |
    {
      "Network": "10.244.0.0/16",
      "Backend": {
        "Type": "vxlan"
      }
    }
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: kube-flannel-ds
  namespace: kube-flannel
  labels:
    tier: node
    app: flannel
    k8s-app: flannel
spec:
  selector:
    matchLabels:
      app: flannel
  template:
    metadata:
      labels:
        tier: node
        app: flannel
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: kubernetes.io/os
                operator: In
                values:
                - linux
      hostNetwork: true
      priorityClassName: system-node-critical
      tolerations:
      - operator: Exists
        effect: NoSchedule
      serviceAccountName: flannel
      initContainers:
      - name: install-cni-plugin
        image: docker.io/flannel/flannel-cni-plugin:v1.1.2
       #image: docker.io/rancher/mirrored-flannelcni-flannel-cni-plugin:v1.1.2
        command:
        - cp
        args:
        - -f
        - /flannel
        - /opt/cni/bin/flannel
        volumeMounts:
        - name: cni-plugin
          mountPath: /opt/cni/bin
      - name: install-cni
        image: docker.io/flannel/flannel:v0.22.0
       #image: docker.io/rancher/mirrored-flannelcni-flannel:v0.22.0
        command:
        - cp
        args:
        - -f
        - /etc/kube-flannel/cni-conf.json
        - /etc/cni/net.d/10-flannel.conflist
        volumeMounts:
        - name: cni
          mountPath: /etc/cni/net.d
        - name: flannel-cfg
          mountPath: /etc/kube-flannel/
      containers:
      - name: kube-flannel
        image: docker.io/flannel/flannel:v0.22.0
       #image: docker.io/rancher/mirrored-flannelcni-flannel:v0.22.0
        command:
        - /opt/bin/flanneld
        args:
        - --ip-masq
        - --kube-subnet-mgr
        resources:
          requests:
            cpu: "100m"
            memory: "50Mi"
        securityContext:
          privileged: false
          capabilities:
            add: ["NET_ADMIN", "NET_RAW"]
        env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: EVENT_QUEUE_DEPTH
          value: "5000"
        volumeMounts:
        - name: run
          mountPath: /run/flannel
        - name: flannel-cfg
          mountPath: /etc/kube-flannel/
        - name: xtables-lock
          mountPath: /run/xtables.lock
      volumes:
      - name: run
        hostPath:
          path: /run/flannel
      - name: cni-plugin
        hostPath:
          path: /opt/cni/bin
      - name: cni
        hostPath:
          path: /etc/cni/net.d
      - name: flannel-cfg
        configMap:
          name: kube-flannel-cfg
      - name: xtables-lock
        hostPath:
          path: /run/xtables.lock
          type: FileOrCreate
# 執(zhí)行安裝

kubectl apply -f kubu-flannel.yml

檢測服務(wù)是否正常運行

#獲取節(jié)點信息
kubectl get nodes

# 查看所有pod 節(jié)點
kubectl get pod -A

# 檢查集群健康狀態(tài)
kubectl get cs

到此,k8s的集群就部署完成了。下面還需要部署kuboard UI頁面。

安裝kuboard UI頁面

# 本次采用在線安裝方式

kubectl apply -f https://kuboard.cn/install-script/kuboard.yaml

kubectl apply -f https://addons.kuboard.cn/metrics-server/0.3.6/metrics-server.yaml

# 查看 Kuboard 運行狀態(tài)
kubectl get pods -l k8s.kuboard.cn/name=kuboard -n kube-system

獲取管理員權(quán)限Token

echo $(kubectl -n kube-system get secret $(kubectl -n kube-system get secret | grep kuboard-user | awk '{print $1}') -o go-template='{{.data.token}}' | base64 -d)

訪問kuboard UI頁面

# 查看pod 節(jié)點信息,獲取Kuboard 服務(wù)的IP地址,便于瀏覽器訪問Kuboard UI頁面
kubectl get pod -n kube-system -o wide

獲取到kuboard UI頁面的IP是192.168.31.8,默認(rèn)端口是32567,我們直接瀏覽器訪問:

粘貼我們剛才獲取到的Token,就可以進行登錄了

到此,k8s集群搭建完成!

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論