工具介绍:
Calico的二进制程序文件calicoctl可以直接操作Calico存储来查看,修改或配置Calico系统特性。
三种方式部署calicoctl:①二进制安装;②docker安装;③运行于kubernetes系统中
这里采用第一种方式:二进制安装
官网:https://docs.projectcalico.org/v3.6/getting-started/calicoctl/install
测试环境:
同上一篇k8s集群环境,如下
System | Hostname | IP | calicoctl位置 |
CentOS 7.6 | k8s-master | 138.138.82.14 | 仅在master安装该命令 |
CentOS 7.6 | k8s-node1 | 138.138.82.15 | — |
CentOS 7.6 | k8s-node2 | 138.138.82.16 | — |
具体步骤:
1. 下载二进制文件
[root@k8s-master ~]# wget https://github.com/projectcalico/calicoctl/releases/download/v3.5.4/calicoctl -O /usr/bin/calicoctl
[root@k8s-master ~]# chmod +x /usr/bin/calicoctl
2. 添加calicoctl配置文件
calicoctl通过读写calico的数据存储系统(datastore)进行查看或者其他各类管理操作,通常,它需要提供认证信息经由相应的数据存储完成认证。在使用Kubernetes API数据存储时,需要使用类似kubectl的认证信息完成认证。它可以通过环境变量声明的DATASTORE_TYPE和KUBECONFIG接入集群,例如以下命令格式运行calicoctl:
[root@k8s-master ~]# DATASTORE_TYPE=kubernetes KUBECONFIG=~/.kube/config calicoctl get nodes
NAME
k8s-master
k8s-node1
k8s-node2
也可以直接将认证信息等保存于配置文件中,calicoctl默认加载 /etc/calico/calicoctl.cfg 配置文件读取配置信息,如下所示:
[root@k8s-master ~]# cat /etc/calico/calicoctl.cfg
apiVersion: projectcalico.org/v3
kind: CalicoAPIConfig
metadata:
spec:
datastoreType: "kubernetes"
kubeconfig: "/root/.kube/config"
[root@k8s-master ~]# calicoctl get nodes
NAME
k8s-master
k8s-node1
k8s-node2
3. 测试calicoctl命令
[root@k8s-master ~]# calicoctl node status
Calico process is running. IPv4 BGP status
+---------------+-------------------+-------+----------+-------------+
| PEER ADDRESS | PEER TYPE | STATE | SINCE | INFO |
+---------------+-------------------+-------+----------+-------------+
| 138.138.82.15 | node-to-node mesh | up | :: | Established |
| 138.138.82.16 | node-to-node mesh | up | :: | Established |
+---------------+-------------------+-------+----------+-------------+ IPv6 BGP status
No IPv6 peers found.
[root@k8s-master ~]# calicoctl get ipPool -o yaml
apiVersion: projectcalico.org/v3
items:
- apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
creationTimestamp: --28T08::12Z
name: default-ipv4-ippool
resourceVersion: ""
uid: 0df17422--11e9-bde3-
spec:
blockSize:
cidr: 192.168.0.0/
ipipMode: Always
natOutgoing: true
nodeSelector: all()
kind: IPPoolList
metadata:
……
以上就是calicoctl命令的简单安装和测试。
结束.