How to set dynamic values with Kubernetes yaml file

前端 未结 13 2067
旧巷少年郎
旧巷少年郎 2020-12-04 16:22

For example, a deployment yaml file:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: guestbook
spec:
  replicas: 2
  template:
    metadata         


        
13条回答
  •  佛祖请我去吃肉
    2020-12-04 16:49

    Helm is exactly meant for such things and a lot more. It handle complex set of resource deployment as a group etc.

    But if we are still looking for some simple alternative then how about using ant?

    If you want to modify the file as part of build process or test process then you can go with ant task as well.

    Using ant you can load all environment values as property or you can simply load properties file like:

    
    
    

    Then you can have a target which converts template files into your desired yaml file.

    
    
        
        
    
            
            
    
            
            
    
            
            
                
            
        
    
    

    Of course you can use a fileset instead of file in case you want to change values dynamically for multiple files (nested or whatever)

    Your template file xyz.template.yml should look like:

    apiVersion: v1
    kind: Service
    metadata:
      name: ${XYZ_RES_NAME}-ser
      labels:
        app: ${XYZ_RES_NAME}
        version: v1
    spec:
      type: NodePort
      ports:
        - port: ${env.XYZ_RES_PORT}
          protocol: TCP
      selector:
        app: ${XYZ_RES_NAME}
        version: v1
    

    env. property being loaded from environment variables and other from property file

    Hope it helped :)

提交回复
热议问题