github.com/containerd/Containerd@v1.4.13/script/setup/install-cni (about)

     1  #!/usr/bin/env bash
     2  
     3  #   Copyright The containerd Authors.
     4  
     5  #   Licensed under the Apache License, Version 2.0 (the "License");
     6  #   you may not use this file except in compliance with the License.
     7  #   You may obtain a copy of the License at
     8  
     9  #       http://www.apache.org/licenses/LICENSE-2.0
    10  
    11  #   Unless required by applicable law or agreed to in writing, software
    12  #   distributed under the License is distributed on an "AS IS" BASIS,
    13  #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  #   See the License for the specific language governing permissions and
    15  #   limitations under the License.
    16  
    17  #
    18  # Builds and installs cni plugins to /opt/cni/bin,
    19  # and create basic cni config in /etc/cni/net.d.
    20  # The commit defined in vendor.conf
    21  #
    22  set -eu -o pipefail
    23  
    24  CNI_COMMIT=$(grep containernetworking/plugins "$GOPATH"/src/github.com/containerd/containerd/vendor.conf | awk '{print $2}')
    25  CNI_DIR=${DESTDIR:=''}/opt/cni
    26  CNI_CONFIG_DIR=${DESTDIR}/etc/cni/net.d
    27  
    28  git clone https://github.com/containernetworking/plugins.git "$GOPATH"/src/github.com/containernetworking/plugins
    29  cd "$GOPATH"/src/github.com/containernetworking/plugins
    30  git checkout $CNI_COMMIT
    31  ./build_linux.sh
    32  sudo mkdir -p $CNI_DIR
    33  sudo cp -r ./bin $CNI_DIR
    34  sudo mkdir -p $CNI_CONFIG_DIR
    35  cat << EOF | sudo tee $CNI_CONFIG_DIR/10-containerd-net.conflist
    36  {
    37    "cniVersion": "0.4.0",
    38    "name": "containerd-net",
    39    "plugins": [
    40      {
    41        "type": "bridge",
    42        "bridge": "cni0",
    43        "isGateway": true,
    44        "ipMasq": true,
    45        "promiscMode": true,
    46        "ipam": {
    47          "type": "host-local",
    48          "ranges": [
    49            [{
    50              "subnet": "10.88.0.0/16"
    51            }],
    52            [{
    53              "subnet": "2001:4860:4860::/64"
    54            }]
    55          ],
    56          "routes": [
    57            { "dst": "0.0.0.0/0" },
    58            { "dst": "::/0" }
    59          ]
    60        }
    61      },
    62      {
    63        "type": "portmap",
    64        "capabilities": {"portMappings": true}
    65      }
    66    ]
    67  }
    68  EOF