首页 > 其他分享 >Flannel HOST-GW 模式

Flannel HOST-GW 模式

时间:2024-08-14 14:40:45浏览次数:13  
标签:GW kube name 10.244 HOST ff Flannel cni flannel

Flannel UDP 模式

一、环境信息

主机 IP
ubuntu 172.16.94.141
软件 版本
docker 26.1.4
helm v3.15.0-rc.2
kind 0.18.0
clab 0.54.2
kubernetes 1.23.4
ubuntu os Ubuntu 20.04.6 LTS
kernel 5.11.5 内核升级文档

二、安装服务

kind 配置文件信息

$ cat install.sh

#!/bin/bash
date
set -v

# 1.prep noCNI env
cat <<EOF | kind create cluster --name=flannel-host-gw --image=kindest/node:v1.23.4 --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
  # kind 默认使用 rancher cni,cni 我们需要自己创建
  disableDefaultCNI: true
  # 定义节点使用的 pod 网段
  podSubnet: "10.244.0.0/16"
nodes:
  - role: control-plane
  - role: worker
  - role: worker

containerdConfigPatches:
- |-
  [plugins."io.containerd.grpc.v1.cri".registry.mirrors."harbor.evescn.com"]
    endpoint = ["https://harbor.evescn.com"]
EOF

# 2.install cni
kubectl apply -f ./flannel.yaml

# 3.install necessary tools
# cd /opt/
# curl -o calicoctl -O -L "https://gh.api.99988866.xyz/https://github.com/containernetworking/plugins/releases/download/v0.9.0/cni-plugins-linux-amd64-v0.9.0.tgz" 
# tar -zxvf cni-plugins-linux-amd64-v0.9.0.tgz

for i in $(docker ps -a --format "table {{.Names}}" | grep flannel) 
do
    echo $i
    docker cp /opt/bridge $i:/opt/cni/bin/
    docker cp /usr/bin/ping $i:/usr/bin/ping
    docker exec -it $i bash -c "sed -i -e 's/jp.archive.ubuntu.com\|archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list"
    docker exec -it $i bash -c "apt-get -y update >/dev/null && apt-get -y install net-tools tcpdump lrzsz bridge-utils >/dev/null 2>&1"
done
  • flannel.yaml
配置文件
# flannel.yaml
---
kind: Namespace
apiVersion: v1
metadata:
  name: kube-flannel
  labels:
    pod-security.kubernetes.io/enforce: privileged
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: flannel
rules:
- apiGroups:
  - ""
  resources:
  - pods
  verbs:
  - get
- apiGroups:
  - ""
  resources:
  - nodes
  verbs:
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - nodes/status
  verbs:
  - patch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: flannel
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: flannel
subjects:
- kind: ServiceAccount
  name: flannel
  namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: flannel
  namespace: kube-system
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: kube-flannel-cfg
  namespace: kube-system
  labels:
    tier: node
    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": "host-gw"
      }
    }
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: kube-flannel-ds
  namespace: kube-system
  labels:
    tier: node
    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: harbor.dayuan1997.com/devops/rancher/mirrored-flannelcni-flannel-cni-plugin:v1.1.0
        command:
        - cp
        args:
        - -f
        - /flannel
        - /opt/cni/bin/flannel
        volumeMounts:
        - name: cni-plugin
          mountPath: /opt/cni/bin
      - name: install-cni
        image: harbor.dayuan1997.com/devops/rancher/mirrored-flannelcni-flannel:v0.19.2
        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: harbor.dayuan1997.com/devops/rancher/mirrored-flannelcni-flannel:v0.19.2
        command:
        - /opt/bin/flanneld
        args:
        - --ip-masq
        - --kube-subnet-mgr
        resources:
          requests:
            cpu: "100m"
            memory: "50Mi"
          limits:
            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
        - name: tun
          mountPath: /dev/net/tun
      volumes:
      - name: tun
        hostPath:
          path: /dev/net/tun
      - 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

flannel.yaml 参数解释

  1. Backend.Type
    • 含义: 用于指定 flannel 工作模式。
    • host-gw: flannel 工作在 host gw 模式。
  • 安装 k8s 集群和 flannel 服务
# ./install.sh

Creating cluster "flannel-host-gw" ...
 ✓ Ensuring node image (kindest/node:v1.23.4) 

标签:GW,kube,name,10.244,HOST,ff,Flannel,cni,flannel
From: https://www.cnblogs.com/evescn/p/18358916

相关文章

  • 在K8S中,flannel和calico的区别?
    在Kubernetes(K8S)中,Flannel和Calico是两种常用的网络插件,它们各自具有不同的特点和应用场景。以下是Flannel和Calico在多个方面的详细区别:1.技术基础与数据平面实现Flannel:使用虚拟网络(如VXLAN或UDP)来实现数据平面。通过封装和解封装技术,将容器的网络流量封装在UDP或VXLAN包......
  • 在K8S中,你用的flannel是哪个工作模式及fannel的底层原理如何实现数据报文转发的?
    在Kubernetes(K8S)中,Flannel是一个广泛使用的容器网络接口(CNI)插件,它提供了一种简单而有效的方法来为集群中的每个容器分配网络,并确保它们可以互相通信。Flannel支持多种工作模式来实现数据报文的转发,其中最常见的是VXLAN、UDP和HOST-GW三种模式。1.Flannel的工作模式VXLAN模式:......
  • flannel容器启动失败,日志报错“Failed to find any valid interface to use: failed t
    现状k8s部署,flannel容器起不来,不断重启,查看日志报错"Failedtofindanyvalidinterfacetouse:failedtogetdefaultinterface:Unabletofinddefaultroute"排查过程根据报错提示,可能是网卡名称奇怪导致,或者没有默认路由查看默认路由很显然是有默认路由的查......
  • 安装local-path-provisioner基于HostPath动态制备PV
    目录一、背景二、安装local-path-provisioner1、地址2、更改local-path-provisioner使用的默认存储路径3、创建文件并提权4、创建NameSpace5、应用local-path-storage6、验证相关资源状态三、设置local-path为defaultSC四、使用StorageClass动态制备PV1、创建PVC2、创建......
  • smbmap报[*] Detected 0 hosts serving SMB
    执行smbmapsmbmap-H{target_ip}显示[*]Detected0hostsservingSMB[*]Closed0connectionsvps连目标机时正常,vps距离目标时延较低抓包显示本机直接syn, syn+ack,第三个包直接rst怀疑是timeout设置问题查看帮助mansmbmap发现可以设置--timeout,默认0.5s......
  • fiftyone localhost:5151页面打开空白 error: disallowed MIME type (“text/plain”)
    解决办法:您必须更改两个键的注册表设置。打开注册表编辑器并前往Computer\HKEY_CLASSES_ROOT\.js并更改ContentType为application/javascript前往Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.js并更改 ContentType为application/javascript。然后只需重新启动shell......
  • K8S中,flannel有几种模式?
    在Kubernetes(K8S)中,Flannel作为一个流行的容器网络接口(CNI)插件,用于为集群中的容器提供网络互通能力。Flannel支持多种模式来实现其网络功能,主要包括以下几种常见模式:1.VXLAN模式描述:VXLAN(VirtualExtensibleLAN)是Flannel的默认后端驱动,它使用VXLAN封装技术来创建跨节点的虚拟......
  • 在K8S中,flannel可以固定节点IP和Pod的IP地址吗?
    在Kubernetes中,Flannel负责为Pod提供跨节点的网络连接,但它本身并不直接分配Pod的IP地址。Pod的IP地址是由Kubernetes的网络插件分配的,Flannel只是在这个过程中起到辅助作用。然而,Flannel可以配置为使用特定的网络模式,以支持更灵活的IP地址管理。以下是一些与IP地址管理相关的方面......
  • 十万个为什么 [CMake] Windows MinGW Cmake
    搜索cmakegenerator 在settings.json里面添加"cmake.preferredGenerators":[    "MinGWMakefiles"  ]  cmake_minimum_required(VERSION3.0.0)project(idatalinkVERSION0.1.0)if(CMAKE_BUILD_TYPESTREQUAL"Release")......
  • ssh 远程登录报错:Unable to negotiate with IP port 22: no matching host key type f
    最近在Mac上想要远程一台Linux服务器,结果不知怎么的就不能使用以前的ssh登录了iot@ios-iMac~%[email protected]:nomatchinghostkeytypefound.Theiroffer:ssh-rsa,ssh-dss ......