mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
835 lines
33 KiB
HTML
835 lines
33 KiB
HTML
<!doctype html>
|
|
<html lang="en" class="no-js">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
<meta name="generator" content="Hugo 0.73.0-DEV" />
|
|
|
|
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
|
|
|
|
<link rel="alternate" type="application/rss+xml" href="https://kubernetes-sigs.github.io/kustomize/guides/components/index.xml">
|
|
|
|
|
|
<link rel="shortcut icon" href="/favicons/favicon.ico" >
|
|
<link rel="apple-touch-icon" href="/kustomize/favicons/apple-touch-icon-180x180.png" sizes="180x180">
|
|
<link rel="icon" type="image/png" href="/kustomize/favicons/favicon-16x16.png" sizes="16x16">
|
|
<link rel="icon" type="image/png" href="/kustomize/favicons/favicon-32x32.png" sizes="32x32">
|
|
<link rel="icon" type="image/png" href="/kustomize/favicons/android-36x36.png" sizes="36x36">
|
|
<link rel="icon" type="image/png" href="/kustomize/favicons/android-48x48.png" sizes="48x48">
|
|
<link rel="icon" type="image/png" href="/kustomize/favicons/android-72x72.png" sizes="72x72">
|
|
<link rel="icon" type="image/png" href="/kustomize/favicons/android-96x96.png" sizes="96x96">
|
|
<link rel="icon" type="image/png" href="/kustomize/favicons/android-144x144.png" sizes="144x144">
|
|
<link rel="icon" type="image/png" href="/kustomize/favicons/android-192x192.png" sizes="192x192">
|
|
|
|
<title>Kustomize Components | Kustomize</title><meta property="og:title" content="Kustomize Components" />
|
|
<meta property="og:description" content="Kustomize components guide
|
|
" />
|
|
<meta property="og:type" content="website" />
|
|
<meta property="og:url" content="https://kubernetes-sigs.github.io/kustomize/guides/components/" />
|
|
<meta property="og:site_name" content="Kustomize" />
|
|
<meta itemprop="name" content="Kustomize Components">
|
|
<meta itemprop="description" content="Kustomize components guide
|
|
"><meta name="twitter:card" content="summary"/>
|
|
<meta name="twitter:title" content="Kustomize Components"/>
|
|
<meta name="twitter:description" content="Kustomize components guide
|
|
"/>
|
|
|
|
|
|
|
|
|
|
|
|
<link rel="preload" href="/kustomize/scss/main.min.818a933df0186c907f1faea6730835dd5fa01c3b53af36bb68396dc80a2d3c45.css" as="style">
|
|
<link href="/kustomize/scss/main.min.818a933df0186c907f1faea6730835dd5fa01c3b53af36bb68396dc80a2d3c45.css" rel="stylesheet" integrity="">
|
|
|
|
|
|
<script
|
|
src="https://code.jquery.com/jquery-3.3.1.min.js"
|
|
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
|
|
crossorigin="anonymous"></script>
|
|
|
|
|
|
|
|
<link rel="stylesheet" type="text/css" href="https://kubernetes-sigs.github.io/kustomize//css/asciinema-player.css" />
|
|
|
|
<title>Kustomize Components | Kustomize</title>
|
|
</head>
|
|
<body class="td-section">
|
|
<header>
|
|
|
|
<nav class="js-navbar-scroll navbar navbar-expand navbar-dark flex-column flex-md-row td-navbar">
|
|
<a class="navbar-brand" href="/kustomize/">
|
|
<span class="navbar-logo"></span><span class="text-uppercase font-weight-bold">Kustomize</span>
|
|
</a>
|
|
<div class="td-navbar-nav-scroll ml-md-auto" id="main_navbar">
|
|
<ul class="navbar-nav mt-2 mt-lg-0">
|
|
|
|
|
|
<li class="nav-item mr-4 mb-2 mb-lg-0">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a class="nav-link" href="/kustomize/installation/" ><span>Installation</span></a>
|
|
</li>
|
|
|
|
<li class="nav-item mr-4 mb-2 mb-lg-0">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a class="nav-link active" href="/kustomize/guides/" ><span class="active">Guides</span></a>
|
|
</li>
|
|
|
|
<li class="nav-item mr-4 mb-2 mb-lg-0">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a class="nav-link" href="/kustomize/api-reference/" ><span>API Reference</span></a>
|
|
</li>
|
|
|
|
<li class="nav-item mr-4 mb-2 mb-lg-0">
|
|
|
|
|
|
|
|
|
|
<a class="nav-link" href="https://github.com/kubernetes-sigs/kustomize/tree/master/examples" target="_blank" ><span>Example</span></a>
|
|
</li>
|
|
|
|
<li class="nav-item mr-4 mb-2 mb-lg-0">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a class="nav-link" href="/kustomize/faq/" ><span>FAQ</span></a>
|
|
</li>
|
|
|
|
<li class="nav-item mr-4 mb-2 mb-lg-0">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a class="nav-link" href="/kustomize/blog/" ><span>Blog</span></a>
|
|
</li>
|
|
|
|
<li class="nav-item mr-4 mb-2 mb-lg-0">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a class="nav-link" href="/kustomize/contributing/" ><span>Contributing</span></a>
|
|
</li>
|
|
|
|
|
|
|
|
<li class="nav-item dropdown d-none d-lg-block">
|
|
|
|
|
|
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
English
|
|
</a>
|
|
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
|
|
|
<a class="dropdown-item" href="/kustomize/zh/">简体中文</a>
|
|
|
|
</div>
|
|
</li>
|
|
|
|
</ul>
|
|
</div>
|
|
<div class="navbar-nav d-none d-lg-block">
|
|
</div>
|
|
</nav>
|
|
|
|
</header>
|
|
<div class="container-fluid td-outer">
|
|
<div class="td-main">
|
|
<div class="row flex-xl-nowrap">
|
|
<div class="col-12 col-md-3 col-xl-2 td-sidebar d-print-none">
|
|
|
|
|
|
|
|
|
|
|
|
<div id="td-sidebar-menu" class="td-sidebar__inner">
|
|
|
|
<form class="td-sidebar__search d-flex align-items-center">
|
|
|
|
|
|
<button class="btn btn-link td-sidebar__toggle d-md-none p-0 ml-3 fas fa-bars" type="button" data-toggle="collapse" data-target="#td-section-nav" aria-controls="td-docs-nav" aria-expanded="false" aria-label="Toggle section navigation">
|
|
</button>
|
|
</form>
|
|
|
|
<nav class="collapse td-sidebar-nav pt-2 pl-4" id="td-section-nav">
|
|
|
|
<div class="nav-item dropdown d-block d-lg-none">
|
|
|
|
|
|
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
English
|
|
</a>
|
|
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
|
|
|
<a class="dropdown-item" href="/kustomize/zh/">简体中文</a>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<ul class="td-sidebar-nav__section pr-md-3">
|
|
<li class="td-sidebar-nav__section-title">
|
|
<a href="/kustomize/guides/" class="align-left pl-0 pr-2 td-sidebar-link td-sidebar-link__section">Guides</a>
|
|
</li>
|
|
<ul>
|
|
<li class="collapse show" id="kustomizeguides">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<ul class="td-sidebar-nav__section pr-md-3">
|
|
<li class="td-sidebar-nav__section-title">
|
|
<a href="/kustomize/guides/bespoke/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">Bespoke Application</a>
|
|
</li>
|
|
<ul>
|
|
<li class="collapse " id="kustomizeguidesbespoke">
|
|
|
|
|
|
|
|
</li>
|
|
</ul>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<ul class="td-sidebar-nav__section pr-md-3">
|
|
<li class="td-sidebar-nav__section-title">
|
|
<a href="/kustomize/guides/offtheshelf/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">Off The Shelf Application</a>
|
|
</li>
|
|
<ul>
|
|
<li class="collapse " id="kustomizeguidesofftheshelf">
|
|
|
|
|
|
|
|
</li>
|
|
</ul>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<ul class="td-sidebar-nav__section pr-md-3">
|
|
<li class="td-sidebar-nav__section-title">
|
|
<a href="/kustomize/guides/plugins/" class="align-left pl-0 pr-2 collapsed td-sidebar-link td-sidebar-link__section">Kustomize Plugins</a>
|
|
</li>
|
|
<ul>
|
|
<li class="collapse " id="kustomizeguidesplugins">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a class="td-sidebar-link td-sidebar-link__page " id="m-kustomizeguidespluginsbuiltins" href="/kustomize/guides/plugins/builtins/">Builtin Plugins</a>
|
|
|
|
|
|
|
|
|
|
|
|
<a class="td-sidebar-link td-sidebar-link__page " id="m-kustomizeguidespluginsexecpluginguidedexample" href="/kustomize/guides/plugins/execpluginguidedexample/">Exec plugin on linux</a>
|
|
|
|
|
|
|
|
|
|
|
|
<a class="td-sidebar-link td-sidebar-link__page " id="m-kustomizeguidespluginsgoplugincaveats" href="/kustomize/guides/plugins/goplugincaveats/">Go plugin Caveats</a>
|
|
|
|
|
|
|
|
|
|
|
|
<a class="td-sidebar-link td-sidebar-link__page " id="m-kustomizeguidespluginsgopluginguidedexample" href="/kustomize/guides/plugins/gopluginguidedexample/">Go plugin example</a>
|
|
|
|
|
|
</li>
|
|
</ul>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<ul class="td-sidebar-nav__section pr-md-3">
|
|
<li class="td-sidebar-nav__section-title">
|
|
<a href="/kustomize/guides/components/" class="align-left pl-0 pr-2 active td-sidebar-link td-sidebar-link__section">Kustomize Components</a>
|
|
</li>
|
|
<ul>
|
|
<li class="collapse show" id="kustomizeguidescomponents">
|
|
|
|
|
|
|
|
</li>
|
|
</ul>
|
|
</ul>
|
|
|
|
|
|
|
|
</li>
|
|
</ul>
|
|
</ul>
|
|
|
|
</nav>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
<div class="d-none d-xl-block col-xl-2 td-toc d-print-none">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="td-page-meta ml-2 pb-1 pt-2 mb-0">
|
|
|
|
|
|
|
|
|
|
|
|
<a href="https://github.com/kubernetes-sigs/kustomize/edit/master/site/content/en/guides/components/_index.md" target="_blank"><i class="fa fa-edit fa-fw"></i> Edit this page</a>
|
|
<a href="https://github.com/kubernetes-sigs/kustomize/issues/new?title=Kustomize%20Components" target="_blank"><i class="fab fa-github fa-fw"></i> Create documentation issue</a>
|
|
|
|
|
|
<a href="https://github.com/kubernetes-sigs/kustomize/issues/new" target="_blank"><i class="fas fa-tasks fa-fw"></i> Create project issue</a>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
<main class="col-12 col-md-9 col-xl-8 pl-md-5" role="main">
|
|
|
|
|
|
|
|
<nav aria-label="breadcrumb" class="d-none d-md-block d-print-none">
|
|
<ol class="breadcrumb spb-1">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<li class="breadcrumb-item" >
|
|
<a href="https://kubernetes-sigs.github.io/kustomize/guides/">Guides</a>
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li class="breadcrumb-item active" aria-current="page">
|
|
<a href="https://kubernetes-sigs.github.io/kustomize/guides/components/">Kustomize Components</a>
|
|
</li>
|
|
|
|
</ol>
|
|
</nav >
|
|
|
|
|
|
<div class="td-content">
|
|
<h1>Kustomize Components</h1>
|
|
<div class="lead">Kustomize components guide</div>
|
|
<p>As of <code>v3.7.0</code> Kustomize supports a special type of kustomization that allows
|
|
one to define reusable pieces of configuration logic that can be included from
|
|
multiple overlays.</p>
|
|
<p>Components come in handy when dealing with applications that support multiple
|
|
optional features and you wish to enable only a subset of them in different
|
|
overlays, i.e., different features for different environments or audiences.</p>
|
|
<p>For more details regarding this feature you can read the
|
|
<a href="https://github.com/kubernetes/enhancements/blob/master/keps/sig-cli/1802-kustomize-components.md">Kustomize Components KEP</a>.</p>
|
|
<h2 id="use-case">Use case</h2>
|
|
<p>Suppose you’ve written a very simple Web application:</p>
|
|
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>apps/v1<span style="color:#f8f8f8;text-decoration:underline">
|
|
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>Deployment<span style="color:#f8f8f8;text-decoration:underline">
|
|
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
|
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>example<span style="color:#f8f8f8;text-decoration:underline">
|
|
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
|
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">template</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
|
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
|
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">containers</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
|
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>example<span style="color:#f8f8f8;text-decoration:underline">
|
|
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">image</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>example<span style="color:#000;font-weight:bold">:</span><span style="color:#0000cf;font-weight:bold">1.0</span><span style="color:#f8f8f8;text-decoration:underline">
|
|
</span></code></pre></div><p>You want to deploy a <strong>community</strong> edition of this application as SaaS, so you
|
|
add support for persistence (e.g. an external database), and bot detection
|
|
(e.g. Google reCAPTCHA).</p>
|
|
<p>You’ve now attracted <strong>enterprise</strong> customers who want to deploy it
|
|
on-premises, so you add LDAP support, and disable Google reCAPTCHA. At the same
|
|
time, the <strong>devs</strong> need to be able to test parts of the application, so they
|
|
want to deploy it with some features enabled and others not.</p>
|
|
<p>Here’s a matrix with the deployments of this application and the features
|
|
enabled for each one:</p>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th></th>
|
|
<th align="center">External DB</th>
|
|
<th align="center">LDAP</th>
|
|
<th align="center">reCAPTCHA</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>Community</td>
|
|
<td align="center">✔️</td>
|
|
<td align="center"></td>
|
|
<td align="center">✔️</td>
|
|
</tr>
|
|
<tr>
|
|
<td>Enterprise</td>
|
|
<td align="center">✔️</td>
|
|
<td align="center">✔️</td>
|
|
<td align="center"></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Dev</td>
|
|
<td align="center">✅</td>
|
|
<td align="center">✅</td>
|
|
<td align="center">✅</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>(✔️ enabled, ✅: optional)</p>
|
|
<p>So, you want to make it easy to deploy your application in any of the above
|
|
three environments. Here’s how you can do this with Kustomize components: each
|
|
opt-in feature gets packaged as a component, so that it can be referred to from
|
|
multiple higher-level overlays.</p>
|
|
<p>First, define a place to work:</p>
|
|
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000">DEMO_HOME</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#204a87;font-weight:bold">$(</span>mktemp -d<span style="color:#204a87;font-weight:bold">)</span>
|
|
</code></pre></div><p>Define a common <strong>base</strong> that has a <code>Deployment</code> and a simple <code>ConfigMap</code>, that
|
|
is mounted on the application’s container.</p>
|
|
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000">BASE</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">$DEMO_HOME</span>/base
|
|
mkdir <span style="color:#000">$BASE</span>
|
|
|
|
cat <span style="color:#4e9a06"><<EOF >$BASE/kustomization.yaml
|
|
</span><span style="color:#4e9a06">resources:
|
|
</span><span style="color:#4e9a06">- deployment.yaml
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06">configMapGenerator:
|
|
</span><span style="color:#4e9a06">- name: conf
|
|
</span><span style="color:#4e9a06"> literals:
|
|
</span><span style="color:#4e9a06"> - main.conf=|
|
|
</span><span style="color:#4e9a06"> color=cornflower_blue
|
|
</span><span style="color:#4e9a06"> log_level=info
|
|
</span><span style="color:#4e9a06">EOF</span>
|
|
|
|
cat <span style="color:#4e9a06"><<EOF >$BASE/deployment.yaml
|
|
</span><span style="color:#4e9a06">apiVersion: apps/v1
|
|
</span><span style="color:#4e9a06">kind: Deployment
|
|
</span><span style="color:#4e9a06">metadata:
|
|
</span><span style="color:#4e9a06"> name: example
|
|
</span><span style="color:#4e9a06">spec:
|
|
</span><span style="color:#4e9a06"> template:
|
|
</span><span style="color:#4e9a06"> spec:
|
|
</span><span style="color:#4e9a06"> containers:
|
|
</span><span style="color:#4e9a06"> - name: example
|
|
</span><span style="color:#4e9a06"> image: example:1.0
|
|
</span><span style="color:#4e9a06"> volumeMounts:
|
|
</span><span style="color:#4e9a06"> - name: conf
|
|
</span><span style="color:#4e9a06"> mountPath: /etc/config
|
|
</span><span style="color:#4e9a06"> volumes:
|
|
</span><span style="color:#4e9a06"> - name: conf
|
|
</span><span style="color:#4e9a06"> configMap:
|
|
</span><span style="color:#4e9a06"> name: conf
|
|
</span><span style="color:#4e9a06">EOF</span>
|
|
</code></pre></div><p>Define an <code>external_db</code> component, using <code>kind: Component</code>, that creates a
|
|
<code>Secret</code> for the DB password and a new entry in the <code>ConfigMap</code>:</p>
|
|
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000">EXT_DB</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">$DEMO_HOME</span>/components/external_db
|
|
mkdir -p <span style="color:#000">$EXT_DB</span>
|
|
|
|
cat <span style="color:#4e9a06"><<EOF >$EXT_DB/kustomization.yaml
|
|
</span><span style="color:#4e9a06">apiVersion: kustomize.config.k8s.io/v1alpha1 # <-- Component notation
|
|
</span><span style="color:#4e9a06">kind: Component
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06">secretGenerator:
|
|
</span><span style="color:#4e9a06">- name: dbpass
|
|
</span><span style="color:#4e9a06"> files:
|
|
</span><span style="color:#4e9a06"> - dbpass.txt
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06">patchesStrategicMerge:
|
|
</span><span style="color:#4e9a06"> - configmap.yaml
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06">patchesJson6902:
|
|
</span><span style="color:#4e9a06">- target:
|
|
</span><span style="color:#4e9a06"> group: apps
|
|
</span><span style="color:#4e9a06"> version: v1
|
|
</span><span style="color:#4e9a06"> kind: Deployment
|
|
</span><span style="color:#4e9a06"> name: example
|
|
</span><span style="color:#4e9a06"> path: deployment.yaml
|
|
</span><span style="color:#4e9a06">EOF</span>
|
|
|
|
cat <span style="color:#4e9a06"><<EOF >$EXT_DB/deployment.yaml
|
|
</span><span style="color:#4e9a06">- op: add
|
|
</span><span style="color:#4e9a06"> path: /spec/template/spec/volumes/0
|
|
</span><span style="color:#4e9a06"> value:
|
|
</span><span style="color:#4e9a06"> name: dbpass
|
|
</span><span style="color:#4e9a06"> secret:
|
|
</span><span style="color:#4e9a06"> secretName: dbpass
|
|
</span><span style="color:#4e9a06">- op: add
|
|
</span><span style="color:#4e9a06"> path: /spec/template/spec/containers/0/volumeMounts/0
|
|
</span><span style="color:#4e9a06"> value:
|
|
</span><span style="color:#4e9a06"> mountPath: /var/run/secrets/db/
|
|
</span><span style="color:#4e9a06"> name: dbpass
|
|
</span><span style="color:#4e9a06">EOF</span>
|
|
|
|
cat <span style="color:#4e9a06"><<EOF >$EXT_DB/configmap.yaml
|
|
</span><span style="color:#4e9a06">apiVersion: v1
|
|
</span><span style="color:#4e9a06">kind: ConfigMap
|
|
</span><span style="color:#4e9a06">metadata:
|
|
</span><span style="color:#4e9a06"> name: conf
|
|
</span><span style="color:#4e9a06">data:
|
|
</span><span style="color:#4e9a06"> db.conf: |
|
|
</span><span style="color:#4e9a06"> endpoint=127.0.0.1:1234
|
|
</span><span style="color:#4e9a06"> name=app
|
|
</span><span style="color:#4e9a06"> user=admin
|
|
</span><span style="color:#4e9a06"> pass=/var/run/secrets/db/dbpass.txt
|
|
</span><span style="color:#4e9a06">EOF</span>
|
|
</code></pre></div><p>Define an <code>ldap</code> component, that creates a <code>Secret</code> for the LDAP password
|
|
and a new entry in the <code>ConfigMap</code>:</p>
|
|
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000">LDAP</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">$DEMO_HOME</span>/components/ldap
|
|
mkdir -p <span style="color:#000">$LDAP</span>
|
|
|
|
cat <span style="color:#4e9a06"><<EOF >$LDAP/kustomization.yaml
|
|
</span><span style="color:#4e9a06">apiVersion: kustomize.config.k8s.io/v1alpha1
|
|
</span><span style="color:#4e9a06">kind: Component
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06">secretGenerator:
|
|
</span><span style="color:#4e9a06">- name: ldappass
|
|
</span><span style="color:#4e9a06"> files:
|
|
</span><span style="color:#4e9a06"> - ldappass.txt
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06">patchesStrategicMerge:
|
|
</span><span style="color:#4e9a06"> - configmap.yaml
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06">patchesJson6902:
|
|
</span><span style="color:#4e9a06">- target:
|
|
</span><span style="color:#4e9a06"> group: apps
|
|
</span><span style="color:#4e9a06"> version: v1
|
|
</span><span style="color:#4e9a06"> kind: Deployment
|
|
</span><span style="color:#4e9a06"> name: example
|
|
</span><span style="color:#4e9a06"> path: deployment.yaml
|
|
</span><span style="color:#4e9a06">EOF</span>
|
|
|
|
cat <span style="color:#4e9a06"><<EOF >$LDAP/deployment.yaml
|
|
</span><span style="color:#4e9a06">- op: add
|
|
</span><span style="color:#4e9a06"> path: /spec/template/spec/volumes/0
|
|
</span><span style="color:#4e9a06"> value:
|
|
</span><span style="color:#4e9a06"> name: ldappass
|
|
</span><span style="color:#4e9a06"> secret:
|
|
</span><span style="color:#4e9a06"> secretName: ldappass
|
|
</span><span style="color:#4e9a06">- op: add
|
|
</span><span style="color:#4e9a06"> path: /spec/template/spec/containers/0/volumeMounts/0
|
|
</span><span style="color:#4e9a06"> value:
|
|
</span><span style="color:#4e9a06"> mountPath: /var/run/secrets/ldap/
|
|
</span><span style="color:#4e9a06"> name: ldappass
|
|
</span><span style="color:#4e9a06">EOF</span>
|
|
|
|
cat <span style="color:#4e9a06"><<EOF >$LDAP/configmap.yaml
|
|
</span><span style="color:#4e9a06">apiVersion: v1
|
|
</span><span style="color:#4e9a06">kind: ConfigMap
|
|
</span><span style="color:#4e9a06">metadata:
|
|
</span><span style="color:#4e9a06"> name: conf
|
|
</span><span style="color:#4e9a06">data:
|
|
</span><span style="color:#4e9a06"> ldap.conf: |
|
|
</span><span style="color:#4e9a06"> endpoint=ldap://ldap.example.com
|
|
</span><span style="color:#4e9a06"> bindDN=cn=admin,dc=example,dc=com
|
|
</span><span style="color:#4e9a06"> pass=/var/run/secrets/ldap/ldappass.txt
|
|
</span><span style="color:#4e9a06">EOF</span>
|
|
</code></pre></div><p>Define a <code>recaptcha</code> component, that creates a <code>Secret</code> for the reCAPTCHA
|
|
site/secret keys and a new entry in the <code>ConfigMap</code>:</p>
|
|
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000">RECAPTCHA</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">$DEMO_HOME</span>/components/recaptcha
|
|
mkdir -p <span style="color:#000">$RECAPTCHA</span>
|
|
|
|
cat <span style="color:#4e9a06"><<EOF >$RECAPTCHA/kustomization.yaml
|
|
</span><span style="color:#4e9a06">apiVersion: kustomize.config.k8s.io/v1alpha1
|
|
</span><span style="color:#4e9a06">kind: Component
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06">secretGenerator:
|
|
</span><span style="color:#4e9a06">- name: recaptcha
|
|
</span><span style="color:#4e9a06"> files:
|
|
</span><span style="color:#4e9a06"> - site_key.txt
|
|
</span><span style="color:#4e9a06"> - secret_key.txt
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06"># Updating the ConfigMap works with generators as well.
|
|
</span><span style="color:#4e9a06">configMapGenerator:
|
|
</span><span style="color:#4e9a06">- name: conf
|
|
</span><span style="color:#4e9a06"> behavior: merge
|
|
</span><span style="color:#4e9a06"> literals:
|
|
</span><span style="color:#4e9a06"> - recaptcha.conf=|
|
|
</span><span style="color:#4e9a06"> enabled=true
|
|
</span><span style="color:#4e9a06"> site_key=/var/run/secrets/recaptcha/site_key.txt
|
|
</span><span style="color:#4e9a06"> secret_key=/var/run/secrets/recaptcha/secret_key.txt
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06">patchesJson6902:
|
|
</span><span style="color:#4e9a06">- target:
|
|
</span><span style="color:#4e9a06"> group: apps
|
|
</span><span style="color:#4e9a06"> version: v1
|
|
</span><span style="color:#4e9a06"> kind: Deployment
|
|
</span><span style="color:#4e9a06"> name: example
|
|
</span><span style="color:#4e9a06"> path: deployment.yaml
|
|
</span><span style="color:#4e9a06">EOF</span>
|
|
|
|
cat <span style="color:#4e9a06"><<EOF >$RECAPTCHA/deployment.yaml
|
|
</span><span style="color:#4e9a06">- op: add
|
|
</span><span style="color:#4e9a06"> path: /spec/template/spec/volumes/0
|
|
</span><span style="color:#4e9a06"> value:
|
|
</span><span style="color:#4e9a06"> name: recaptcha
|
|
</span><span style="color:#4e9a06"> secret:
|
|
</span><span style="color:#4e9a06"> secretName: recaptcha
|
|
</span><span style="color:#4e9a06">- op: add
|
|
</span><span style="color:#4e9a06"> path: /spec/template/spec/containers/0/volumeMounts/0
|
|
</span><span style="color:#4e9a06"> value:
|
|
</span><span style="color:#4e9a06"> mountPath: /var/run/secrets/recaptcha/
|
|
</span><span style="color:#4e9a06"> name: recaptcha
|
|
</span><span style="color:#4e9a06">EOF</span>
|
|
</code></pre></div><p>Define a <code>community</code> variant, that bundles the external DB and reCAPTCHA
|
|
components:</p>
|
|
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000">COMMUNITY</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">$DEMO_HOME</span>/overlays/community
|
|
mkdir -p <span style="color:#000">$COMMUNITY</span>
|
|
|
|
cat <span style="color:#4e9a06"><<EOF >$COMMUNITY/kustomization.yaml
|
|
</span><span style="color:#4e9a06">apiVersion: kustomize.config.k8s.io/v1beta1
|
|
</span><span style="color:#4e9a06">kind: Kustomization
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06">resources:
|
|
</span><span style="color:#4e9a06"> - ../../base
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06">components:
|
|
</span><span style="color:#4e9a06"> - ../../components/external_db
|
|
</span><span style="color:#4e9a06"> - ../../components/recaptcha
|
|
</span><span style="color:#4e9a06">EOF</span>
|
|
</code></pre></div><p>Define an <code>enterprise</code> overlay, that bundles the external DB and LDAP
|
|
components:</p>
|
|
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000">ENTERPRISE</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">$DEMO_HOME</span>/overlays/enterprise
|
|
mkdir -p <span style="color:#000">$ENTERPRISE</span>
|
|
|
|
cat <span style="color:#4e9a06"><<EOF >$ENTERPRISE/kustomization.yaml
|
|
</span><span style="color:#4e9a06">apiVersion: kustomize.config.k8s.io/v1beta1
|
|
</span><span style="color:#4e9a06">kind: Kustomization
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06">resources:
|
|
</span><span style="color:#4e9a06"> - ../../base
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06">components:
|
|
</span><span style="color:#4e9a06"> - ../../components/external_db
|
|
</span><span style="color:#4e9a06"> - ../../components/ldap
|
|
</span><span style="color:#4e9a06">EOF</span>
|
|
</code></pre></div><p>Define a <code>dev</code> overlay, that points to all the components and has LDAP
|
|
disabled:</p>
|
|
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000">DEV</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">$DEMO_HOME</span>/overlays/dev
|
|
mkdir -p <span style="color:#000">$DEV</span>
|
|
|
|
cat <span style="color:#4e9a06"><<EOF >$DEV/kustomization.yaml
|
|
</span><span style="color:#4e9a06">apiVersion: kustomize.config.k8s.io/v1beta1
|
|
</span><span style="color:#4e9a06">kind: Kustomization
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06">resources:
|
|
</span><span style="color:#4e9a06"> - ../../base
|
|
</span><span style="color:#4e9a06">
|
|
</span><span style="color:#4e9a06">components:
|
|
</span><span style="color:#4e9a06"> - ../../components/external_db
|
|
</span><span style="color:#4e9a06"> #- ../../components/ldap
|
|
</span><span style="color:#4e9a06"> - ../../components/recaptcha
|
|
</span><span style="color:#4e9a06">EOF</span>
|
|
</code></pre></div><p>Now, the workspace has the following directories:</p>
|
|
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">├── base
|
|
│ ├── deployment.yaml
|
|
│ └── kustomization.yaml
|
|
├── components
|
|
│ ├── external_db
|
|
│ │ ├── configmap.yaml
|
|
│ │ ├── dbpass.txt
|
|
│ │ ├── deployment.yaml
|
|
│ │ └── kustomization.yaml
|
|
│ ├── ldap
|
|
│ │ ├── configmap.yaml
|
|
│ │ ├── deployment.yaml
|
|
│ │ ├── kustomization.yaml
|
|
│ │ └── ldappass.txt
|
|
│ └── recaptcha
|
|
│ ├── deployment.yaml
|
|
│ ├── kustomization.yaml
|
|
│ ├── secret_key.txt
|
|
│ └── site_key.txt
|
|
└── overlays
|
|
├── community
|
|
│ └── kustomization.yaml
|
|
├── dev
|
|
│ └── kustomization.yaml
|
|
└── enterprise
|
|
└── kustomization.yaml
|
|
</code></pre></div><p>With this structure, you can generate the YAML manifests for each deployment
|
|
using <code>kustomize build</code>:</p>
|
|
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kustomize build overlays/community
|
|
kustomize build overlays/enterprise
|
|
kustomize build overlays/dev
|
|
</code></pre></div>
|
|
<div class="section-index">
|
|
|
|
|
|
|
|
|
|
<hr class="panel-line">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="text-muted mt-5 pt-3 border-top">Last modified July 6, 2020: <a href="https://github.com/kubernetes-sigs/kustomize/commit/1b531c6ac737065d574a9c9f2cdf98cf2873c79e">docs: Add guide for components (1b531c6a)</a>
|
|
</div>
|
|
</div>
|
|
|
|
</main>
|
|
</div>
|
|
</div>
|
|
|
|
<footer class="bg-dark py-5 row d-print-none">
|
|
<div class="container-fluid mx-sm-5">
|
|
<div class="row">
|
|
<div class="col-6 col-sm-4 text-xs-center order-sm-2">
|
|
|
|
|
|
|
|
<ul class="list-inline mb-0">
|
|
|
|
<li class="list-inline-item mx-2 h3" data-toggle="tooltip" data-placement="top" title="User mailing list" aria-label="User mailing list">
|
|
<a class="text-white" target="_blank" href="https://groups.google.com/forum/#!forum/kubernetes-sig-cli">
|
|
<i class="fa fa-envelope"></i>
|
|
</a>
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
</div>
|
|
<div class="col-6 col-sm-4 text-right text-xs-center order-sm-3">
|
|
|
|
|
|
|
|
<ul class="list-inline mb-0">
|
|
|
|
<li class="list-inline-item mx-2 h3" data-toggle="tooltip" data-placement="top" title="GitHub" aria-label="GitHub">
|
|
<a class="text-white" target="_blank" href="https://github.com/kubernetes-sigs/kustomize">
|
|
<i class="fab fa-github"></i>
|
|
</a>
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
</div>
|
|
<div class="col-12 col-sm-4 text-center py-2 order-sm-2">
|
|
<small class="text-white">© 2020 Kubernetes Authors All Rights Reserved</small>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
|
|
|
|
</div>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
|
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script src="/kustomize/js/main.min.35b203b3c2114e187f6e4bbf0903c511aaaac5535186321e3b5e364656b6de0c.js" integrity="sha256-NbIDs8IRThh/bku/CQPFEaqqxVNRhjIeO142Rla23gw=" crossorigin="anonymous"></script>
|
|
|
|
|
|
|
|
<script src="https://kubernetes-sigs.github.io/kustomize//js/asciinema-player.js"></script>
|
|
|
|
|
|
</body>
|
|
</html> |