关键命令

kubectl get deployment.apps -n kube-system           

                     资源类型                  命名空间

kubectl get deployment.apps/calico-kube-controllers -n kube-system -o yaml > calico.yaml
                           名字                                                                       打印成yaml   生成为yaml文件

 cat calico.yaml -n |grep image:
      查找image 的关键字

 sed -n 's/harbor.ceclouddyn.com/harbor.wlc.intranet.cecloudcs.com/g' calico.yaml
                     旧的                                       新的                                           文件名

sed -i “s/oldstring/newstring/g” grep oldstring -rl /modules

systemd

 实例代码


#!/bin/bash

set -xe
echo $0
kubectl get deployment.apps/calico-kube-controllers -n kube-system -o yaml > /tmp/calico-kube-controllers.yaml
kubectl get deployment.apps/calico-typha -n kube-system -o yaml >/tmp/calico-typha.yaml
command ||  (echo "command failed"; echo 1) ; 
kubectl get deployment.apps/coredns -n kube-system -o yaml > /tmp/coredns.yaml
kubectl get daemonset.apps/calico-node -n kube-system -o yaml > /tmp/calico-node.yaml
kubectl get daemonset.apps/kube-cni-blackhole -n kube-system -o yaml > /tmp/kube-cni-blackhole.yaml
kubectl get daemonset.apps/kube-proxy -n kube-system -o yaml > /tmp/kube-proxy.yaml


OD_name=(harbor.wlc.intranet.cecloudcs.com harbor.cestc.com har.wlc.cecdev.cn)
for i in ${OD_name[@]};
do
str=$i

eval sed -i 's/$str/harbor.ceclouddyn.com/g' /tmp/calico-kube-controllers.yaml;
eval sed -i 's/$str/harbor.ceclouddyn.com/g' /tmp/calico-typha.yaml;
eval sed -i 's/$str/harbor.ceclouddyn.com/g' /tmp/coredns.yaml;
eval sed -i 's/$str/harbor.ceclouddyn.com/g' /tmp/calico-node.yaml;
eval sed -i 's/$str/harbor.ceclouddyn.com/g' /tmp/kube-cni-blackhole.yaml;
eval sed -i 's/$str/harbor.ceclouddyn.com/g' /tmp/kube-proxy.yaml;

done

kubectl apply -f /tmp/calico-kube-controllers.yaml
kubectl apply -f /tmp/calico-typha.yaml
kubectl apply -f /tmp/coredns.yaml
kubectl apply -f /tmp/calico-node.yaml
kubectl apply -f /tmp/kube-cni-blackhole.yaml
kubectl apply -f /tmp/kube-proxy.yaml

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐