0
点赞
收藏
分享

微信扫一扫

k8s源码学习-资源转换器

笙烛 2022-03-26 阅读 59

在Kubernetes系统中,同一资源拥有多个资源版本,Kubernetes系统允许同一资源的不同资源版本进行转换,例如Deployment资源对象,当前运行的是v1beta1资源版本,但v1beta1资源版本的某些功能或字段不如v1资源版本完善,则可以将Deployment资源对象的v1beta1资源版本转换为v1版本。可通过kubectl convert命令进行资源版本转换

kubectl convert 默认没有安装,安装方法参考:​​安装 kubectl convert 插件​​

比如:我定义了一个 v1beta1deploy.yaml

apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

创建deployment报错了,我想把它转为v1版本再创建,命令:

kubectl convert -f /tmp/deployment.yaml --output-version=apps/v1 > /tmp/v1deploy.yaml

➜  ~ kubectl create -f /tmp/deployment.yaml
error: unable to recognize "/tmp/deployment.yaml": no matches for kind "Deployment" in version "apps/v1beta1"
➜ ~ kubectl convert -f /tmp/deployment.yaml --output-version=apps/v1
kubectl convert is DEPRECATED and will be removed in a future version.
In order to convert, kubectl apply the object to the cluster, then kubectl get at the desired version.
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: nginx
name: nginx-deployment
spec:
progressDeadlineSeconds: 600
replicas: 3
revisionHistoryLimit: 2
selector:
matchLabels:
app: nginx
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: nginx
spec:
containers:
- image: nginx:1.14.2
imagePullPolicy: IfNotPresent
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: {}
➜ ~ kubectl convert -f /tmp/deployment.yaml --output-version=apps/v1 > /tmp/v1deploy.yaml
kubectl convert is DEPRECATED and will be removed in a future version.
In order to convert, kubectl apply the object to the cluster, then kubectl get at the desired version.
➜ ~ kubectl create -f /tmp/v1deploy.yaml
deployment.apps/nginx-deployment created
➜ ~ kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default nginx-deployment-9456bbbf9-78z87 1/1 Running 0 27s
default nginx-deployment-9456bbbf9-7tgnm 1/1 Running 0 27s
default nginx-deployment-9456bbbf9-n4mch 1/1 Running 0 27s


举报

相关推荐

0 条评论