为什么选择kube-vip不解释,因为它更科学

# 官网
# https://kube-vip.io/docs/installation/static/
# https://github.com/kube-vip/kube-vip
# 拉取一个镜像
ctr images pull ghcr.io/kube-vip/kube-vip:v0.7.0

# 做个临时别名
alias kube-vip="ctr run --rm --net-host ghcr.io/kube-vip/kube-vip:v0.7.0 vip /kube-vip"
#国内镜像
registry.cn-shenzhen.aliyuncs.com/neway-sz/uat:vip070
创建一个静态pod配置
# kube-vip manifest pod \
    --interface ens32 \
    --address 172.18.1.181 \  ----vip 
    --controlplane \
    --services \
    --arp \
    --leaderElection | tee /etc/kubernetes/manifests/kube-vip.yaml
root@master-60:~# cat  kube-vip.yaml 
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  name: kube-vip
  namespace: kube-system
spec:
  containers:
  - args:
    - manager
    env:
    - name: vip_arp
      value: "true"
    - name: port
      value: "6443"
    - name: vip_interface
      value: enp1s0
    - name: vip_cidr
      value: "32"
    - name: dns_mode
      value: first
    - name: cp_enable
      value: "true"
    - name: cp_namespace
      value: kube-system
    - name: svc_enable
      value: "true"
    - name: svc_leasename
      value: plndr-svcs-lock
    - name: vip_leaderelection
      value: "true"
    - name: vip_leasename
      value: plndr-cp-lock
    - name: vip_leaseduration
      value: "5"
    - name: vip_renewdeadline
      value: "3"
    - name: vip_retryperiod
      value: "1"
    - name: address
      value: 192.168.0.66 ------你的vip 
    - name: prometheus_server
      value: :2112
    image: registry.cn-shenzhen.aliyuncs.com/neway-sz/uat:vip070 --镜像
    #image: ghcr.io/kube-vip/kube-vip:v0.7.0
    name: kube-vip
    resources: {}
    securityContext:
      capabilities:
        add:
        - NET_ADMIN
        - NET_RAW
    volumeMounts:
    - mountPath: /etc/kubernetes/admin.conf
      name: kubeconfig
  hostAliases:
  - hostnames:
    - kubernetes
    ip: 127.0.0.1
  hostNetwork: true
  volumes:
  - hostPath:
      path: /etc/kubernetes/admin.conf
    name: kubeconfig
status: {}

K8S相关文件

初始化集群配置
# kubeadm config print init-defaults --component-configs KubeletConfiguration > kubeadm.yaml

编辑kubeadm.yaml

apiVersion: kubeadm.k8s.io/v1beta3
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 172.18.1.171 <<<<----当前node节点IP
  bindPort: 6443
nodeRegistration:
  criSocket: /var/run/containerd/containerd.sock
  imagePullPolicy: IfNotPresent
  name: node171
  taints: null
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns:
  type: CoreDNS   <<<<<<<<<---
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: k8s.gcr.io
kind: ClusterConfiguration
kubernetesVersion: 1.23.8
controlPlaneEndpoint: 172.18.1.181:6443 <<<<<<-----vip
networking:
  dnsDomain: cluster.local
  podSubnet: 100.64.0.0/10 <<<< ---自定义pods ip 
  serviceSubnet: 10.96.0.0/12
scheduler: {}
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: ipvs
---
apiVersion: kubelet.config.k8s.io/v1beta1
authentication:
  anonymous:
    enabled: false
  webhook:
    cacheTTL: 0s
    enabled: true
  x509:
    clientCAFile: /etc/kubernetes/pki/ca.crt
authorization:
  mode: Webhook
  webhook:
    cacheAuthorizedTTL: 0s
    cacheUnauthorizedTTL: 0s
cgroupDriver: systemd
clusterDNS:
- 10.96.0.10
clusterDomain: cluster.local
cpuManagerReconcilePeriod: 0s
evictionPressureTransitionPeriod: 0s
fileCheckFrequency: 0s
healthzBindAddress: 127.0.0.1
healthzPort: 10248
httpCheckFrequency: 0s
imageMinimumGCAge: 0s
kind: KubeletConfiguration
logging:
  flushFrequency: 0
  options:
    json:
      infoBufferSize: "0"
  verbosity: 0
memorySwap: {}
nodeStatusReportFrequency: 0s
nodeStatusUpdateFrequency: 0s
rotateCertificates: true
runtimeRequestTimeout: 0s
shutdownGracePeriod: 0s
shutdownGracePeriodCriticalPods: 0s
staticPodPath: /etc/kubernetes/manifests
streamingConnectionIdleTimeout: 0s
syncFrequency: 0s
volumeStatsAggPeriod: 0s

查看拉取镜像

# kubeadm config images pull --config kubeadm.yaml

初始化集群
# kubeadm init --upload-certs --config kubeadm.yaml --v=6

再创建一个高可用的vip

kube-vip manifest daemonset \
    --interface ens32 \
    --address 172.18.1.181 \
    --inCluster \
    --taint \
    --controlplane \
    --services \
    --arp \
    --leaderElection | tee daemonset-kube-vip.yaml

自己添加一下时区(不在乎时间可以跳过此步)

        image: ghcr.io/kube-vip/kube-vip:v0.7.0
        imagePullPolicy: IfNotPresent
        name: kube-vip
        resources: {}
        volumeMounts:
          - mountPath: /etc/localtime
            name: timezone
        securityContext:
          capabilities:
            add:
            - NET_ADMIN
            - NET_RAW
            - SYS_TIME
      hostNetwork: true
      volumes:
        - name: timezone
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai

重新创建

# kubectl apply -f https://kube-vip.io/manifests/rbac.yaml
# kubectl apply -f daemonset-kube-vip.yaml

==最后再将刚才的静态pods移除 ==

# mv /etc/kubernetes/manifests/kube-vip.yaml /tmp/kube-vip.yaml
或者删除 
# rm -f /etc/kubernetes/manifests/kube-vip.yaml

在这里插入图片描述
在这里插入图片描述

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐