Kustomize install

参考 https://kubectl.docs.kubernetes.io/installation/kustomize/

最容易的应该是直接使用 二进制 文件

https://github.com/kubernetes-sigs/kustomize/releases

sudo chmod a+x kustomize /usr/local/sbin
sudo cp kustomize /usr/local/sbin

我们来尝试一个helloworld

先编写一个 nginx 的 deploy

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    workload.user.cattle.io/workloadselector: deployment-lizhe-nginx
  name: nginx
  namespace: lizhe
spec:
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      workload.user.cattle.io/workloadselector: deployment-lizhe-nginx
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        workload.user.cattle.io/workloadselector: deployment-lizhe-nginx
    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: nginx
        resources: {}
        stdin: true
        tty: true
      restartPolicy: Always
      terminationGracePeriodSeconds: 30

创建一个空文件

kustomization.yaml

然后使用 kustomize cli 来对其添加内容

kustomize edit add resource nginx.yaml

下面我们尝试使用 kustomize edit 给它加一个前缀

需要先修改 kustomization.yaml

kustomize edit set nameprefix 'prod-'

执行

kustomize build ./

你也可以直接应用到集群

kustomize build ./  | kubectl apply -f -
Send a Message