kustomize 模版自由的配置&&自定义kubernetes工具

kustomize 是一个可以方便我们基于模版配置,自定义kubernetes 的工具,类似kompose,但是个人觉得kompose
更灵活点,而且使用上更方便

安装

mac

brew install kustomize

基本使用

  • 创建kustomization.yaml 文件(类似docker-compose)
touch kustomization.yaml
内容如下:
   commonLabels:
     app: hello
   resources:
   - deployment.yaml
   - configMap.yaml
   - service.yaml

如下:

  • resource 定义
deploy:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: appdmeo
spec:
  selector:
    matchLabels:
      app: appdmeo
  template:
    metadata:
      labels:
        app: appdmeo
    spec:
      containers:
      - name: appdmeo
        image: nginx
        ports:
        - containerPort: 80
service:
kind: Service
apiVersion: v1
metadata:
  name: appdemo
spec:
  selector:
    app: appdmeo
  type: NodePort
  ports:
  - name: http
    port: 80
    targetPort: 80

configmap:
apiVersion: v1
kind: ConfigMap
metadata:
  name: myconfigmap
  labels:
    app: myapplication
data:
  username: dalongdemo
  • 构建
kustomize build

生成的内容

apiVersion: v1
data:
  username: dalongdemo
kind: ConfigMap
metadata:
  labels:
    app: hello
  name: myconfigmap
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: hello
  name: appdemo
spec:
  ports:
  - name: http
    port: 80
    targetPort: 80
  selector:
    app: hello
  type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: hello
  name: appdmeo
spec:
  selector:
    matchLabels:
      app: hello
  template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
      - image: nginx
        name: appdmeo
        ports:
        - containerPort: 80
  • 支持的命令

参考资料

https://kubernetes.io/blog/2018/05/29/introducing-kustomize-template-free-configuration-customization-for-kubernetes/
https://kustomize.io/
https://github.com/kubernetes-sigs/kustomize
https://www.jianshu.com/p/65490ab651e1?utm_campaign=hugo

posted on 2018-11-27 11:27  荣锋亮  阅读(1048)  评论(0编辑  收藏  举报

导航