kubectl-convert 安装使用
·
介绍kubectl-convert 的安装和使用
1. kubectl-convert作用
将yaml资源清单中废弃的api版本或者旧的api版本转换为指定的版本,默认是转换成最新的版本
2. 安装kubectl-convert
根据官网文件安装即可:https://kubernetes.io/zh-cn/docs/tasks/tools/install-kubectl-linux/#install-kubectl-convert-plugin
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert"
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert.sha256"
echo "$(cat kubectl-convert.sha256) kubectl-convert" | sha256sum --check
install -o root -g root -m 0755 kubectl-convert /usr/local/bin/kubectl-convert
3. 实验
准备一个旧的api版本的yaml文件
kubectl create namespace test
nginx-deploy.yaml:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: nginx-deploy
namespace: test
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
kubectl create -f nginx-deploy.yaml
error: resource mapping not found for name: "nginx-deploy" namespace: "test" from "nginx-deploy.yaml": no matches for kind "Deployment" in version "apps/v1beta1"
ensure CRDs are installed first
如上在"apps/v1beta1"未找到Deployment资源,使用kubectl-convert 将api版本更新到最新:
kubectl convert -f nginx-deploy.yaml > nginx-deploy-v1.yaml
nginx-deploy-v1.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: nginx
name: nginx-deploy
namespace: test
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 2
selector:
matchLabels:
app: nginx
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx:latest
imagePullPolicy: Always
name: nginx
ports:
- containerPort: 80
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status: {}
api版本已经被修改成:apps/v1了,如果要指定版本使用:kubectl convert -f nginx-deploy.yaml --output-version=apps/v1 > nginx-deploy-v2.yaml
kubectl apply -f nginx-deploy-v1.yaml
kubectl get deploy -n test
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deploy 1/1 1 1 76s
更多推荐

所有评论(0)