calico change provider network IP address route via

Patch 

# https://stackoverflow.com/questions/41958475/getting-the-object-array-index-in-jq
# https://www.codegrepper.com/code-examples/javascript/jq+array.length
kubectl get ds calico-node  -n kube-system -o json |jq '.spec.template.spec.containers[0].env | length'
kubectl get ds calico-node  -n kube-system -o json |jq '.spec.template.spec.containers[0].env |map(.name == "IP_AUTODETECTION_METHOD") | index(true)'
kubectl get ds calico-node  -n kube-system -o json |jq '[ .spec.template.spec.containers[0].env | debug | .name == "IP_AUTODETECTION_METHOD" ] | index(true)
kubectl get ds calico-node  -n kube-system -o json |jq '[ .spec.template.spec.containers[0].env | debug | map(.name == "IP_AUTODETECTION_METHOD") ] | index(true)'

LEN=`kubectl get ds calico-node  -n kube-system -o json | \
  jq '.spec.template.spec.containers[0].env | length'`
IDX=$((LEN-1))
IDX=`kubectl get ds calico-node  -n kube-system -o json |jq '.spec.template.spec.containers[0].env | \
  map(.name == "IP_AUTODETECTION_METHOD") | index(true)'`

DS=calico-node

CMPATH=/spec/template/spec/containers/0/env/$IDX/value
VAL="cidr=192.168.10.66/24"

kubectl patch ds/$DS -n kube-system --type='json' -p '[
  {"op":"replace","path":"'"$CMPATH"'","value": "'"$VAL"'"},
]'

 

Add

NM=IP_AUTODETECTION_METHOD
CMPATH=/spec/template/spec/containers/0/env/-
kubectl patch ds/$DS -n kube-system --type='json' -p '[
  {"op":"add","path":"'"$CMPATH"'","value": {"name": "'"$NM"'", "value": "'"$VAL"'"}},
]'

 

Change apiserver listen address after deployment

CLUSTER_PNET=192.168.10.66/24
 
IDX=`kubectl get pods -n kube-system kube-apiserver-controller -o json | \
  jq '.spec.containers[0].command |map(contains("--advertise-address=")) |index(true)'`
 
CMPATH=/spec/containers/0/command/$IDX
VAL="--advertise-address=1${CLUSTER_PNET%/*}"
DS=kube-apiserver-controller
 
kubectl patch pod/$DS -n kube-system --type='json' -p '[
  {"op":"replace","path":"'"$CMPATH"'","value": "'"$VAL"'"},
]'

had better change the ip before development

# CLUSTER_PNET IP 192.168.10.66 is the apiserver IP
CLUSTER_PNET=192.168.10.66/24
 
CON_PATH=roles/kubernetes/controlplane/templates/config.yaml.j2
ls ceek
if [ $? -eq 0 ]; then CON_PATH=ceek/$CON_PATH; fi
sed -i -e "/\(.*\)event-ttl/a \    advertise-address: \"${CLUSTER_PNET%/*}\""  $CON_PATH
 
CON_PATH=roles/kubernetes/cni/calico/controlplane/files/customize_calico_container.yml
ls ceek
if [ $? -eq 0 ]; then CON_PATH=ceek/$CON_PATH; fi
sed -i -e "/\(.*\)IP_AUTODETECTION_METHOD/{n;s/\(value: \).*/\1\"cidr=${CLUSTER_PNET%/*}\/${CLUSTER_PNET#*/}\"/}" $CON_PATH

 

 


 

【Calico系列】2 BGP入门笔记   

【Calico系列】3 Calico的组件、架构与原理

我们可以将 workload(工作负载) 当成容器或者虚拟机。

在 calico 中,计算节点充当了路由器的角色。它们为运行在本机上的容器或是虚拟机提供路由。我们称之为 vRouter。Linux Kernel 负责数据数据包路由, 通过BPG协议来控制路由分发, Flelix 来管理路由信息。

处于节点上的 Endpoint 只能同本节点 vRouter 通信, 数据包的第一条和最后一条都是通过 vRouter 中路由规则来实现。vRouter 间通过BGP协议来同步节点上的 Endpoint 信息。

 

kubernet+calico二进制安装及总结 deployment calico-kube-controllers

Kubernetes网络组件之Calico策略实践(BGP)  

calico学习  

Calico on Kubernetes 从入门到精通  Calico on Kubernetes 从入门到精通

 

calico VPP的实现

VPP dataplane implementation details  

Host network configuration   

 

 

posted @ 2021-05-07 21:42  lvmxh  阅读(87)  评论(0编辑  收藏  举报