Calicoctl工具学习 —— 筑梦之路

127 篇文章 7 订阅
114 篇文章 3 订阅

官方文档:

Calico Documentation | Calico Documentation

插件方式安装 calicoctl 工具

curl -o kubectl-calico -O -L  "https://github.com/projectcalico/calicoctl/releases/download/v3.20.0/calicoctl"

cp kubectl-calico /usr/bin/kubectl-calico

chmod +x /usr/bin/kubectl-calico


kubectl calico -h
Usage:
  kubectl-calico [options] <command> [<args>...]

    create       Create a resource by file, directory or stdin.
    replace      Replace a resource by file, directory or stdin.
    apply        Apply a resource by file, directory or stdin.  This creates a resource
                 if it does not exist, and replaces a resource if it does exists.
    patch        Patch a pre-exisiting resource in place.
    delete       Delete a resource identified by file, directory, stdin or resource type and
                 name.
    get          Get a resource identified by file, directory, stdin or resource type and
                 name.
    label        Add or update labels of resources.
    convert      Convert config files between different API versions.
    ipam         IP address management.
    node         Calico node management.
    version      Display the version of this binary.
    export       Export the Calico datastore objects for migration
    import       Import the Calico datastore objects for migration
    datastore    Calico datastore management.

Options:
  -h --help                 Show this screen.
  -l --log-level=<level>    Set the log level (one of panic, fatal, error,
                            warn, info, debug) [default: panic]
  --context=<context>       The name of the kubeconfig context to use.
  --allow-version-mismatch  Allow client and cluster versions mismatch.

Description:
  The calico kubectl plugin is used to manage Calico network and security
  policy, to view and manage endpoint configuration, and to manage a Calico
  node instance.

  See 'kubectl-calico <command> --help' to read about a specific subcommand.

calicoctl 是用来管理 calico 自己引入的 API 资源的。calicoctl 使用来专门操作 API Server 或 etcd 中与自己状态相关的数据的命令行工具。

calicoctl 配置文件

calicoctl 与 API Server 通信时是需要 kubeconfig 文件的,所以需要为其提供 kubeconfig 配置文件,当其作为 kubectl 的插件运行时,系统会默认读取 kubectl 的配置文件。

官方文档:https://docs.projectcalico.org/getting-started/clis/calicoctl/configure/

calico 的配置文件默认在 /etc/calico目录下,需要手动创建

mkdir /etc/calico

cd /etc/calico

# 在此目录下创建一个 calicoctl.cfg 的配置文件,再其内部申明后端存储类型,和 kubeconfig 的文件路径

vim calicoctl.cfg

apiVersion: projectcalico.org/v3
kind: CalicoAPIConfig
metadata:
spec:
  datastoreType: "kubernetes"        # 此处申明后端存储为kubernetes
  kubeconfig: "/root/.kube/config"   # 因为后端存储为k8s,所以需要kubeconfig文件来指明k8s集群地址已经认证信息。

calicoctl 使用

kubectl calico get nodes

# calico 也能使用 get nodes 此处的 nodes 并非 k8s 节点,而是 calico 的资源


# 此前使用 kubectl get ippools -o yaml 来获取,现在直接使用以下命令即可

kubectl calico get ippool

# calico 支持多个地址池,当一个地址池用完时,可以增加一个地址池
# 只不过跨网段通信略微麻烦

# 查看指定地址池的资源抽象信息

kubectl calico get ippool -o yaml
apiVersion: projectcalico.org/v3
items:
- apiVersion: projectcalico.org/v3
  kind: IPPool
  metadata:
    creationTimestamp: "2024-05-06T06:00:24Z"
    name: default-ipv4-ippool
    resourceVersion: "6789"
    uid: 943b85b2-9759-49ce-8f73-78f1f3f8a111
  spec:
    blockSize: 24
    cidr: 192.168.0.0/16
    ipipMode: Always
    natOutgoing: true
    nodeSelector: all()
    vxlanMode: Never
kind: IPPoolList
metadata:
  resourceVersion: "7984"
ipam 子命令

# 查看地址分配信息

kubectl calico ipam show

# 查看每个节点上的地址分配信息

kubectl calico ipam show --show-blocks

# 查看 ipam 配置信息

kubectl calico ipam show --show-configuration

+--------------------+-------+
|      PROPERTY      | VALUE |
+--------------------+-------+
| StrictAffinity     | false |   # pod被重建后是否使用原有地址
| AutoAllocateBlocks | true  |   # 是否支持自动分配地址
| MaxBlocksPerHost   |     0 |
+--------------------+-------+

 

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Calico是一种开源的容器网络解决方案,可以用于部署和管理容器网络。以下是部署Calico容器网络的步骤: 1. 准备环境:首先,需要确保你的服务器或虚拟机运行在一个支持容器运行环境的操作系统上,例如Linux。还要安装容器运行时,例如Docker或Kubernetes。 2. 下载Calico:在https://docs.projectcalico.org/getting-started/kubernetes/下载Calico的压缩包。将其解压到你选择的目录。 3. 配置Calico网络:通过编辑calico.yaml文件来配置Calico网络。可以设置Pod IP池,网络策略和其他选项。根据你的具体需求,进行相应的配置。 4. 部署Calico:运行calicoctl apply -f calico.yaml命令来部署Calico。该命令会将配置应用到Kubernetes集群中,并启动所需的容器和服务。 5. 验证部署:使用calicoctl命令行工具来验证部署是否成功。运行calicoctl node status命令来查看节点的状态。如果所有节点都处于正常状态,则说明部署成功。 6. 配置网络策略:根据需要,你可以通过calico.yaml文件或使用calicoctl命令行工具来配置网络策略。网络策略可用于控制容器间的网络通信,例如允许或禁止特定的流量。 7. 扩展和管理:在部署成功后,你可以使用calicoctl命令行工具管理Calico网络。你可以添加新的节点,更新配置,监控网络状态,解决故障等。可以根据需要进行扩展和管理。 使用Calico来部署容器网络可以提供可靠和高性能的容器网络解决方案。它支持网络策略,使得可以更好地控制容器间的通信。同时,Calico还提供了丰富的工具和命令,方便管理和扩展容器网络。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值