我的部署 yaml 文件是 bitbucket,用于构建镜像和部署容器的 CI/CD 管道位于 Azure DevOps 中。我能够正确构建和标记图像,即每次运行管道时,图像版本都会增加 1,例如1.0.0、1.0.1、1.0.2 ... 此存储库中没有“最新”标签。我如何在 deployment.yml 文件中动态传递此图像标签,以便 kubectl 部署阶段始终选择最新的标记图像?
我的部署文件目前看起来像:
apiVersion: apps/v1
kind: Deployment
metadata:
name: ubuntu-custom
labels:
app: ubuntu-custom
spec:
replicas: 1
selector:
matchLabels:
app: ubuntu-custom
template:
metadata:
labels:
app: ubuntu-custom
spec:
containers:
- name: ubuntu-custom
image: <acr>/ubuntu-custom:latest
command: ["sleep"]
args: ["365d"]
imagePullSecrets:
- name: acrsecret
我尝试将图像更改为 - image: acr/ubuntu-custom 但出现 ImagePullBackOff 错误。
我确定我需要在部署文件中传递最新标记,但我不确定如何实现。
最佳答案
使用sed命令
sed 's/\\<arc\\>/${ACR_REPO_URL}/g' deploy.yaml
使用yq
yq -i -y ".spec. template.spec.containers.image = \\"${ACR_REPO_URL}\\""
deploy.yaml
关于kubernetes - 如何在部署yaml文件中传递参数化图像标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68750180/