Aller au contenu

~/.calico/calicoctl.cfg

Platform/MéthodeCommande
Operator (Recommended)kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/tigera-operator.yaml
Manifest-Basedkubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/calico.yaml
Helmhelm install calico projectcalico/tigera-operator --namespace tigera-operator --create-namespace
calicoctl (Linux)curl -L https://github.com/projectcalico/calico/releases/download/v3.27.0/calicoctl-linux-amd64 -o calicoctl && chmod +x calicoctl && sudo mv calicoctl /usr/local/bin/
calicoctl (macOS)brew install calicoctl
calicoctl (Windows)Invoke-WebRequest -Uri "https://github.com/projectcalico/calico/releases/download/v3.27.0/calicoctl-windows-amd64.exe" -OutFile "calicoctl.exe"
calicoctl as Podkubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/calicoctl.yaml
Amazon EKSkubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/calico-vxlan.yaml
Azure AKSaz aks create --network-plugin azure --network-policy calico
CommandeDescription
calicoctl versionAfficher les informations de version de Calico
calicoctl node statusAfficher le statut de peering BGP et les routes
calicoctl get nodesListez tous les nœuds exécutant Calico
calicoctl get nodes -o wideLister les nœuds avec des détails supplémentaires
calicoctl get ippoolsAfficher tous les pools d’adresses IP
calicoctl get ippool default-ipv4-ippool -o yamlAfficher la configuration détaillée du pool IP
calicoctl get workloadendpointsLister tous les points de terminaison de charge de travail (pods)
calicoctl get wep --all-namespacesLister les points de terminaison de charge de travail dans tous les espaces de noms
calicoctl get networkpolicyAfficher toutes les network policies
calicoctl get networkpolicy -n NAMESPACELister les politiques dans un namespace spécifique
calicoctl get globalnetworkpolicyAfficher les politiques de réseau globales
calicoctl get profilesLister tous les profils Calico
calicoctl get hostendpointsAfficher les configurations de point de terminaison hôte
kubectl get pods -n calico-systemVérifier le statut des pods système Calico
kubectl get installation default -o yamlAfficher la configuration d’installation de Calico
CommandeDescription
calicoctl apply -f network-policy.yamlAppliquer la politique réseau à partir du fichier
calicoctl delete networkpolicy POLICY_NAME -n NAMESPACESupprimer la politique réseau spécifique
calicoctl get bgpconfig default -o yamlAfficher la configuration BGP
calicoctl get bgppeersLister toutes les configurations de pairs BGP
calicoctl apply -f bgppeer.yamlConfigurer le peering BGP
calicoctl get felixconfiguration default -o yamlAfficher la configuration de Felix (agent)
calicoctl patch felixconfiguration default --patch='{"spec":{"bpfEnabled":true}}'Activer le dataplane eBPF
calicoctl ipam showAfficher les informations d’allocation d’adresses IP
calicoctl ipam show --show-blocksAfficher les blocs d’allocation d’adresses IP détaillés
calicoctl ipam release --ip=IP_ADDRESSLibérer une adresse IP spécifique
calicoctl datastore migrate export > calico-data.yamlExporter le datastore Calico
calicoctl datastore migrate import < calico-data.yamlImporter le datastore Calico
calicoctl get node NODE_NAME -o yamlObtenez la configuration de nœud détaillée
calicoctl patch ippool default-ipv4-ippool -p '{"spec":{"natOutgoing":true}}'Activer NAT pour le pool IP
calicoctl convert -f old-policy.yaml -o new-policy.yamlConvertir la politique vers la nouvelle version de l’API
# ~/.calico/calicoctl.cfg
apiVersion: projectcalico.org/v3
kind: CalicoAPIConfig
metadata:
spec:
  datastoreType: "kubernetes"
  kubeconfig: "/home/user/.kube/config"
```## Utilisation avancée
```bash
export CALICO_DATASTORE_TYPE=kubernetes
export CALICO_KUBECONFIG=~/.kube/config
export CALICO_APICONFIG=/path/to/calicoctl.cfg
```## Configuration
```yaml
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
  name: default-ipv4-ippool
spec:
  cidr: 192.168.0.0/16
  ipipMode: CrossSubnet
  natOutgoing: true
  disabled: false
  blockSize: 26
```### Fichier de configuration calicoctl
```yaml
apiVersion: projectcalico.org/v3
kind: BGPConfiguration
metadata:
  name: default
spec:
  logSeverityScreen: Info
  nodeToNodeMeshEnabled: true
  asNumber: 64512
  serviceClusterIPs:
  - cidr: 10.96.0.0/12
```### Variables d'environnement
```yaml
apiVersion: projectcalico.org/v3
kind: FelixConfiguration
metadata:
  name: default
spec:
  logSeverityScreen: Info
  reportingInterval: 60s
  ipipEnabled: true
  ipipMTU: 1440
  bpfEnabled: false
  wireguardEnabled: false
```### Configuration de pool IP
```bash
# Create deny-all default policy
cat <<EOF | calicoctl apply -f -
apiVersion: projectcalico.org/v3
kind: NetworkPolicy
metadata:
  name: default-deny
  namespace: production
spec:
  selector: all()
  types:
  - Ingress
  - Egress
EOF

# Verify policy
calicoctl get networkpolicy -n production
```### Configuration BGP
```bash
# Allow frontend to backend communication
cat <<EOF | calicoctl apply -f -
apiVersion: projectcalico.org/v3
kind: NetworkPolicy
metadata:
  name: frontend-to-backend
  namespace: production
spec:
  selector: app == 'frontend'
  types:
  - Egress
  egress:
  - action: Allow
    destination:
      selector: app == 'backend'
      ports:
      - 8080
EOF
```### Configuration de Felix
```bash
# Add BGP peer for Top-of-Rack switch
cat <<EOF | calicoctl apply -f -
apiVersion: projectcalico.org/v3
kind: BGPPeer
metadata:
  name: rack1-tor
spec:
  node: k8s-node-01
  peerIP: 192.168.1.1
  asNumber: 64512
EOF

# Verify BGP peering
calicoctl node status
```## Cas d'utilisation courants
```bash
# Enable WireGuard on Felix
calicoctl patch felixconfiguration default --type=merge --patch='{"spec":{"wireguardEnabled":true}}'

# Verify WireGuard status
kubectl get nodes -o yaml | grep wireguard

# Check encryption on specific node
calicoctl get node NODE_NAME -o yaml | grep wireguard
```### Cas d'utilisation 1 : Refuser tout le trafic vers un namespace
```bash
# Create global policy to protect Kubernetes nodes
cat <<EOF | calicoctl apply -f -
apiVersion: projectcalico.org/v3
kind: GlobalNetworkPolicy
metadata:
  name: host-protection
spec:
  selector: has(host-endpoint)
  order: 0
  ingress:
  - action: Allow
    protocol: TCP
    destination:
      ports: [22, 179, 443, 6443]
  - action: Deny
  egress:
  - action: Allow
EOF
```### Cas d'utilisation 2 : Autoriser le trafic entre des pods spécifiques
`bpfEnabled: true`### Cas d'utilisation 3 : Configurer le peering BGP avec un commutateur ToR
`calicoctl node status`### Cas d'utilisation 4 : Activer le chiffrement WireGuard
`blockSize`### Cas d'utilisation 5 : Créer une politique réseau globale pour la protection des hôtes
`order`## Meilleures pratiques
`calicoctl datastore migrate export`- **Utiliser les politiques réseau tôt** : Implémenter des politiques de refus par défaut au niveau du namespace avant de déployer des applications pour appliquer une sécurité zéro confiance dès le départ

- **Exploiter les sélecteurs de libellés** : Utiliser des libellés cohérents et significatifs sur les pods et appliquer des politiques réseau basées sur ces libellés plutôt que sur des adresses IP pour la maintenabilité

- **Activer le dataplane eBPF** : Pour les charges de travail hautes performances, activer le mode eBPF (
| Problème | Solution |
|-------|----------|
| **Pods can't communicate across nodes** | Check BGP peering: `calicoctl node status`. Verify IP pool CIDR doesn't conflict: `calicoctl get ippools` |
| **Network policy not taking effect** | Verify policy selector matches pod labels: `kubectl get pods --show-labels`. Check policy order and types (Ingress/Egress) |
| **High CPU usage on nodes** | Enable eBPF dataplane: `calicoctl patch felixconfiguration default --patch='{"spec":{"bpfEnabled":true}}'` |
| **IP address exhaustion** | Check IP allocation: `calicoctl ipam show --show-blocks`. Increase IP pool size or adjust blockSize |
| **calicoctl commands fail** | Verify datastore config: `echo $CALICO_DATASTORE_TYPE`. Check kubeconfig: `kubectl get nodes` |
| **Calico pods in CrashLoopBackOff** | Check logs: `kubectl logs -n calico-system -l k8s-app=calico-node`. Verify kernel modules: `lsmod | grep ip_tables` |
| **BGP routes not propagating** | Disable node-to-node mesh if using ToR: `calicoctl patch bgpconfig default -p '{"spec":{"nodeToNodeMeshEnabled":false}}'` |
| **MTU issues causing packet loss** | Adjust IPIP MTU: `calicoctl patch felixconfig default -p '{"spec":{"ipipMTU":1440}}'` or disable IPIP |
| **WireGuard encryption not working** | Verify kernel support: `modprobe wireguard && lsmod | grep wireguard`. Check Felix config: `calicoctl get felixconfig default -o yaml` |
| **Workload endpoints not appearing** | Restart calico-node pod: `kubectl delete pod -n calico-system -l k8s-app=calico-node`. Verify CNI config: `cat /etc/cni/net.d/10-calico.conflist` |
## Référence Rapide : Exemples de Politiques

### Autoriser le Trafic DNS

```yaml
apiVersion: projectcalico.org/v3
kind: NetworkPolicy
metadata:
  name: allow-dns
  namespace: default
spec:
  selector: all()
  types:
  - Egress
  egress:
  - action: Allow
    protocol: UDP
    destination:
      selector: k8s-app == 'kube-dns'
      ports: [53]

Autoriser l’Ingress depuis un Namespace Spécifique

apiVersion: projectcalico.org/v3
kind: NetworkPolicy
metadata:
  name: allow-from-frontend
  namespace: backend
spec:
  selector: app == 'api'
  types:
  - Ingress
  ingress:
  - action: Allow
    source:
      namespaceSelector: name == 'frontend'

Limitation de Débit (Politique Globale)

The translations preserve the markdown formatting, keep technical terms in English, and maintain the same structure and punctuation.```yaml apiVersion: projectcalico.org/v3 kind: GlobalNetworkPolicy metadata: name: rate-limit-external spec: selector: role == ‘public-api’ types:

  • Ingress ingress:
  • action: Allow source: notNets: [10.0.0.0/8] metadata: annotations: rate-limit: “100”