<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Adrien Trouillaud on Medium]]></title>
        <description><![CDATA[Stories by Adrien Trouillaud on Medium]]></description>
        <link>https://medium.com/@adrienjt?source=rss-a6d36eaaf61e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zSgA96S6jGlImgHfS-siZA.jpeg</url>
            <title>Stories by Adrien Trouillaud on Medium</title>
            <link>https://medium.com/@adrienjt?source=rss-a6d36eaaf61e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 08:03:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adrienjt/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Imperative vs. Declarative — a Kubernetes Tutorial]]></title>
            <link>https://medium.com/payscale-tech/imperative-vs-declarative-a-kubernetes-tutorial-4be66c5d8914?source=rss-a6d36eaaf61e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4be66c5d8914</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Adrien Trouillaud]]></dc:creator>
            <pubDate>Mon, 15 Apr 2019 13:01:01 GMT</pubDate>
            <atom:updated>2019-04-30T01:09:11.018Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<h3>Imperative vs. Declarative — a Kubernetes Tutorial</h3><p>There are two basic ways to deploy to Kubernetes: <strong>imperatively</strong>, with the many kubectl commands, or <strong>declaratively</strong>, by writing manifests and using kubectl apply. The former is good for learning and interactive experimentation (analogous to a programming language’s <a href="https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop">REPL</a>); the latter is good for reproducible deployments, i.e., for production — though you may still use some kubectl commands for debugging in production.</p><p><em>The Data Science team at PayScale was an early adopter of Kubernetes. I first wrote this tutorial to onboard fellow team members and help spread the use of Kubernetes to the rest of the company. We’re hoping it will help others too.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-_e4zWyIeIYd_4lm" /><figcaption>Photo by <a href="https://unsplash.com/@matthew_t_rader?utm_source=medium&amp;utm_medium=referral">Matthew T Rader</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Prerequisites</h3><p>This tutorial assumes you have access to a cluster. Nowadays, you can <a href="https://kubernetes.io/docs/setup/pick-right-solution/">easily run a single-node cluster on your machine, or create a multi-node cluster in your favorite cloud</a>. Make sure <a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/">kubectl</a> is installed on your machine and properly configured. The following command should succeed:</p><pre>kubectl cluster-info</pre><p>You should also have enough permissions in your default namespace (which may be different than thedefault namespace). The <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles">edit</a> role should be enough. If you created a cluster for this tutorial, you’re likely an <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles">admin</a>, so you&#39;re good to go. Otherwise, somebody may have prepared the ground for you. If you don’t understand this paragraph, just keep going :)</p><p><em>Optional:</em> If you decide to build and push a custom container image (see below), rather than pull a public one, we assume you and the cluster have access to a container image registry. Again, somebody may have prepared the ground for you. <a href="https://cloud.google.com/container-registry/docs/using-with-google-cloud-platform#google-kubernetes-engine">GKE works well with GCR</a>, <a href="https://docs.microsoft.com/en-us/azure/container-registry/container-registry-auth-aks">AKS works well with ACR</a>, etc. Otherwise, <a href="https://hub.docker.com/">DockerHub</a> and <a href="https://quay.io/">Quay</a> are popular options, but if you don’t make your image public, you may need to <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#add-imagepullsecrets-to-a-service-account">configure the default service account in your namespace with an image pull secret</a>.</p><h3>Optional: Build and Push</h3><p>Whether we deploy imperatively or declaratively, we need a container image. You can skip this part and use an existing image if you’re in a hurry, e.g., <a href="https://hub.docker.com/_/nginx">nginx</a>, but some of the steps in this tutorial are tailored for the application we’ll build in this section. Also, if you want to learn how to containerize an application, read on.</p><p>For the purpose of this tutorial, we’ll start with a simple web app’s source code. Here’s a sample Node.js app based on an <a href="https://nodejs.org/en/docs/guides/getting-started-guide/">example from the Node.js documentation</a> (feel free to write an equivalent in your favorite programming language). In an empty folder, copy the code below to a file named app.js:</p><pre>// app.js</pre><pre>const http = require(&#39;http&#39;);<br>const os = require(&#39;os&#39;);</pre><pre>const ip = &#39;0.0.0.0&#39;;<br>const port = 3000;</pre><pre>const hostname = os.hostname();<br>const whoami = process.env[&#39;WHOAMI&#39;] || &#39;Anonymous&#39;;</pre><pre>const server = http.createServer((req, res) =&gt; {<br>  res.statusCode = 200;<br>  res.setHeader(&#39;Content-Type&#39;, &#39;text/plain&#39;);<br>  res.end(`Hi, I’m ${whoami}, from ${hostname}.\n`);<br>});</pre><pre>server.listen(port, ip, () =&gt; {<br>  console.log(`Server running at <a href="http://${ip}:${port}/`);">http://${ip}:${port}/`);</a><br>});</pre><p>We made a few changes to the base example:</p><ul><li><strong>Important!</strong> Serve on 0.0.0.0 rather than 127.0.0.1. The latter is for loopback only and this app will listen to incoming requests on a Cluster IP (captured by 0.0.0.0).</li><li>We also changed the “Hello World” message to include two variables: the hostname, which will be an indicator of which replica is responding, and the WHOAMI environment variable, to be set at deploy time, defaulting to “Anonymous”.</li></ul><p>If you’ve installed Node.js, you can test the app locally:</p><pre>node app.js # then open <a href="http://localhost:3000/">http://localhost:3000</a></pre><p><em>Note:</em> if you’re rolling your own, don’t bother with TLS termination or authentication, because those can be handled at the cluster’s edge by, e.g., <a href="https://www.getambassador.io/">Ambassador</a>, and even between apps within the cluster in a service mesh like <a href="https://istio.io/">Istio</a>, if you decide to go <a href="https://cloud.google.com/beyondcorp/#researchPapers">zero-trust</a>.</p><p>Let’s package this app as a Docker image. Copy the code below to a file named Dockerfile:</p><pre># Dockerfile<br>FROM node:8<br>COPY app.js .<br>ENTRYPOINT [“node”, “app.js”]</pre><p>In the same folder, run:</p><pre>docker build -t myrepo:mytag .</pre><p>Depending on your container image registry, replace myrepo with something like gcr.io/project-name/image-name on GCR, or user-name/image-name on DockerHub (the default registry). Replace mytag with anything but latest. If you’re taking this tutorial with a group of people, make sure you use different tags. Don’t forget the final dot, making the current folder the build context.</p><p>Finally, push the image to your repository (from which Kubernetes will pull):</p><pre>docker push myrepo:mytag</pre><h3>Imperative Configuration</h3><h4>Run</h4><p>The shortest way to deploy to Kubernetes is to use the kubectl run command. Replace myapp with something unique if you’re taking this tutorial with other people and sharing a namespace; replace myrepo:mytag with what you picked in the previous step (or just use nginx):</p><pre>kubectl run myapp --image myrepo:mytag --replicas 2</pre><p>The command may look familiar if you’ve ever used docker run to start a container locally, but the similarity stops here. Here’s what happens under the hood (also illustrated in the diagram below):</p><ol><li>kubectl translates your imperative command into a declarative Kubernetes <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/">Deployment</a> object. A Deployment is a higher-level API that allows rolling updates (see below).</li><li>kubectl sends the Deployment to the Kubernetes API server, kube-apiserver, which runs in-cluster.</li><li>kube-apiserver saves the Deployment to <a href="https://coreos.com/etcd/">etcd</a> (a distributed key-value store), which also runs in-cluster, and responds to kubectl.</li><li>Asynchronously, the Kubernetes controller manager, kube-controller-manager, which watches for Deployment events (among others), creates a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/">ReplicaSet</a> from the Deployment and sends it to kube-apiserver. A ReplicaSet is a version of a Deployment. During a rolling update, a new ReplicaSet will be created and progressively scaled out to the desired number of replicas, while the old one is scaled in to zero.</li><li>kube-apiserver saves the ReplicaSet to etcd.</li><li>Asynchronously, kube-controller-manager, creates two <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/">Pods</a> (or more if we scale out) from the ReplicaSet and sends them to kube-apiserver. <strong>Pods are the basic unit of Kubernetes. They represent one or several containers sharing a </strong><a href="https://itnext.io/chroot-cgroups-and-namespaces-an-overview-37124d995e3d"><strong>Linux cgroup and namespaces</strong></a><strong>.</strong></li><li>kube-apiserver saves the Pods to etcd.</li><li>Asynchronously, the Kubernetes scheduler, kube-scheduler, which watches for Pod events, updates each Pod to assign it to a Node and sends them back to kube-apiserver.</li><li>kube-apiserver saves the Pods to etcd.</li><li>Finally, the kubelet that runs on the assigned Node, always watching, actually starts the container.</li></ol><p><em>Note:</em> the controller, scheduler and kubelet also send status information back to the API server.</p><p>In summary, Kubernetes is a CRUD API with control loops.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ey4tXYIeFRByVHNsvcq7aw.png" /><figcaption>from the <a href="https://book.kubebuilder.io/basics/what_is_a_controller.html">Kubebuilder documentation</a>, licensed under the <a href="https://github.com/kubernetes-sigs/kubebuilder/blob/master/LICENSE">Apache License, Version 2.0</a></figcaption></figure><h4>Get, Describe</h4><p>kubectl run created a Deployment, which rolled out a ReplicaSet of Pods. Where are they? Use kubectl get to list all Deployments, ReplicaSets and Pods in your default namespace:</p><pre>kubectl get deployments # plural or singular, or deploy for short<br>kubectl get replicasets # or rs<br>kubectl get pods # or po</pre><p>To get a single object, add its name as an argument, e.g.:</p><pre>kubectl get deployment myapp</pre><p>To see the object’s state as saved in etcd, use the --output option (or -o):</p><pre>kubectl get deployment myapp -o yaml</pre><p>To gather more details, including recent Events (e.g., errors) related to the object, use the kubectl describe command:</p><pre>kubectl describe deployment myapp</pre><p>Go ahead and run the same commands on the ReplicaSet and Pods.</p><h4>Label</h4><p>Labels are very useful. A label is a key-value pair of strings. All Kubernetes objects can be labeled and those labels can be used as selectors. The kubectl run command added the run=myapp to our Deployment (and the controlled ReplicaSet and Pods) automatically. You saw it in the YAML outputs and descriptions. To see those labels in the regular table output, use the --show-labels option:</p><pre>kubectl get deployments --show-labels<br>kubectl get replicasets --show-labels<br>kubectl get pods --show-labels</pre><p>If you know what keys you’re interested in, use the --label-columns option (or -L) to show the values as columns, e.g.:</p><pre>kubectl get replicasets -L run</pre><p>Most importantly, to filter objects by label, use the --selector option (or -l), e.g.:</p><pre>kubectl get pods -l run=myapp</pre><p>You can also add labels manually, e.g.:</p><pre>kubectl label deployment myapp foo=bar</pre><h4>Delete</h4><p>The Kubernetes API is fundamentally declarative, which means that the controllers always work to reconcile the observed state with the desired state. Therefore, if we delete a Pod, the ReplicaSet controller will create a new one to replace it, to maintain the desired replica count. See for yourself:</p><pre>kubectl delete pods -l run=myapp<br># wait a bit<br>kubectl get pods -l run=myapp</pre><p>Notice that the new Pods have different generated names than the old ones (the random suffix part).</p><p>The same is true for the ReplicaSet. If we delete it, the Deployment controller will create a new one to replace it. But if we delete the Deployment itself, our intent is really to delete the app; nothing controls the Deployment but us.</p><h4>Port-Forward</h4><p>So far, we’ve seen the objects created by Kubernetes in response to kubectl run. Kubernetes indicates that the Pods are ready, simply because the processes in the containers are running. We could define a more significant <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/">liveness probe</a>, but for now, let’s make sure our app works as expected by manually testing it.</p><p>kubectl port-forward proxies a local port (on your machine) to a Pod’s port, via the API server (secured with TLS over the Internet, between the proxy on your machine and the API server). It is a fairly flexible command. If you provide a Pod name and port as arguments, kubectl will simply port-forward to that Pod’s port. But because Pod names are usually generated, including random characters, it is often more convenient to provide the kind/name pair of a controlling object, e.g., a Deployment; kubectl will select a matching Pod for you:</p><pre>kubectl port-forward deployment/myapp 3000</pre><p>Then simply open <a href="http://localhost:3000/">http://localhost:3000/</a> in a browser (or curl in a different terminal) to see the “Hello World” message. The hostname shouldn’t change when you reload because we’re only port-forwarding to one Pod. Also, note that we didn’t set the WHOAMI environment variable when we ran kubectl run; we <em>could have</em>, with the --env option, but we’ll use this omission as an opportunity to learn how to edit a Deployment with kubectl set and kubectl patch in a later step.</p><p>To stop port-forwarding, press Ctrl+C. If the connection is inactive for some time, it will be closed automatically.</p><p><em>Note:</em> you can use a different port locally, e.g., if the Pod’s port is taken on your machine, e.g.:</p><pre>kubectl port-forward deployment/myapp 5000:3000</pre><h4>Expose</h4><p>Our app is working, but other deployed apps (their Pods) shouldn’t have to use port-forward. Pods have Pod IPs and DNS entries. We <em>could</em> use those, but pods are short-lived, their IPs and names keep changing. Also, we need a way to talk to Deployments (or other kinds of Pod groups), not just single Pods. We need <a href="https://www.datawire.io/guide/traffic/service-discovery-microservices/">service discovery</a>.</p><p>A Kubernetes <a href="https://kubernetes.io/docs/concepts/services-networking/service/">Service</a> routes traffic to a set of Pods matching the Service’s label selector. If multiple Pods match the selector, they all listen and receive traffic. To expose a Deployment, we can simply use the Deployment’s selector (in our case, run=app) as the Service’s selector.</p><p>The kubectl expose command automates Service creation from a Deployment, ReplicaSet, or even another Service or a single Pod. It looks up the selector from the given object automatically, unless otherwise specified with options:</p><pre>kubectl expose deployment myapp --port 80 --target-port 3000 # let’s expose on the standard HTTP port, 80, which we couldn’t use on our dev machine</pre><p>Check that the Service was created:</p><pre>kubectl get service # or svc</pre><p>You can see the Pod IPs of the listening Pods in the description of the Service, or in the companion Endpoints object (controlled by the Service). This can be useful to debug networking issues:</p><pre>kubectl describe service myapp<br>kubectl get endpoints myapp</pre><p>Let’s spin up a temporary Pod with an interactive terminal to actually call the Service:</p><pre>kubectl run mytest -it --rm --image alpine # Alpine is tiny</pre><pre># inside mytest:</pre><pre>apk add curl<br>curl <a href="http://myapp/">http://myapp</a> # “Hello World…”<br>exit</pre><p>That deserves a few explanations: kubectl run created a Deployment as before, allocated a TTY (-t or --tty), kept stdin open (-i or --stdin), attached to it, and deleted the Deployment when we exited (--rm). Those options may look familiar as they exist for docker run as well.</p><h4>Logs</h4><p>If our app had issues, we may want to check its logs. Container logs are stored by the container runtime (typically the Docker daemon) on the nodes and automatically rotated, by default, when the log file exceeds 10MB. We could <a href="https://kubernetes.io/docs/concepts/cluster-administration/logging/">set up a logging agent</a> to push the logs to a persistent backend; just remember kubectl logs only sees the logs left on the nodes.</p><p>Just like with port-forward, we can either request the logs of a specific Pod by supplying its name, or request the logs of a group of Pods by supplying the kind/name pair of a controlling object (e.g., a Deployment):</p><pre>kubectl logs deployment/myapp</pre><p>In our case, not much has been logged. However, a production app may be more verbose, especially when you actually need to check the logs (so many errors!). You can limit the output with the --since (e.g., 1m), --since-time (e.g., 2018–11–01T16:30:00) and --tail (e.g., 20 lines) options. Other useful options include --follow (or -f), --previous (when containers keep crashing), and --timestamps (if your app doesn’t log timestamps already). After that, it can be handy to write the output to a file and grep your way around it, e.g.:</p><pre>kubectl logs deployment/myapp --since 5m &gt; log.txt<br>grep error log.txt<br># more grep</pre><h4>Exec, Copy</h4><p>kubectl offers a couple of other tools to help debug running containers. kubectl exec executes a command in a container, and kubectl cp copies files and directories to and from containers. The two commands take explicit Pod names rather than Deployment names. Here’s a useful trick leveraging the --output jsonpath option to store a Pod name in a shell variable:</p><pre>POD_NAME=$(kubectl get pods -l run=myapp -o jsonpath={.items[0].metadata.name})</pre><p>We can then use that variable in the other commands:</p><pre>kubectl exec $POD_NAME -it sh # opens an interactive shell in the container</pre><pre># inside the container, just a few examples:</pre><pre>node --version<br>echo $WHOAMI<br>exit</pre><pre># back to your machine</pre><pre>kubectl cp $POD_NAME:app.js remote-app.js # again, just an example (there are better means to know what code currently runs in production)</pre><h4>Set, Scale, Patch</h4><p>We still need to set the WHOAMI environment variable. We can do that with kubectl set or kubectl patch. While we’re at it, let’s also learn how to watch resource changes with kubectl get --watch (or -w), and observe rolling updates in real time:</p><pre>kubectl get deployment myapp -w</pre><pre># in a second terminal:</pre><pre>kubectl get replicasets -w -l run=myapp</pre><pre># in a third terminal:</pre><pre>kubectl get pods -w -l run=myapp</pre><pre># in a fourth terminal:</pre><pre>kubectl set env deployment/myapp WHOAMI=&quot;HAL 9000&quot;</pre><p>In the first three terminals, observe the creation of a new ReplicaSet, and the orchestrated creation/deletion of new/old Pods. You’ll also see lines corresponding to status changes (look at the numbers of Pods in the DESIRED, CURRENT, UP-TO-DATE, AVAILABLE/READY columns). You’ve just witnessed a rolling update. Let’s scale out our Deployment before we roll out another change:</p><pre>kubectl scale --replicas 3 deployment myapp</pre><p>The kubectl set command is limited to setting environment variables, images, resource requests/limits, selectors, ServiceAccounts, and subjects of RoleBindings (cf. <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/">Role-Based Access Control, or RBAC</a>, which is outside the scope of this tutorial). The kubectl patch command is more general. It accepts JSON or YAML to replace or merge specific fields. As a simplistic example, we’re going to bypass the scheduler and force all Pods to run on one node:</p><p>First, see that our app’s replicas are currently running on different nodes:</p><pre>kubectl get pods -l run=myapp -o wide # check the NODE column</pre><p>Let’s just pick one and patch our Deployment with it:</p><pre>NODE_NAME=$(kubectl get pods -l run=myapp -o jsonpath={.items[0].spec.nodeName})<br>kubectl patch deployment myapp -p &#39;{&quot;spec&quot;:{&quot;template&quot;:{&quot;spec&quot;:{&quot;nodeName&quot;:&quot;&#39;$NODE_NAME&#39;&quot;}}}}&#39;</pre><p>Now all the Pods should be assigned to the same node:</p><pre>kubectl get pods -l run=myapp -o wide</pre><p><em>Note:</em> there are smarter ways to influence the scheduler, like labeling certain nodes and using a <a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector">node selector</a>, <a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity">affinities and anti-affinities</a>, <a href="https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/">taints and tolerations</a>, etc.</p><h3>Declarative Configuration</h3><p>Congratulations! If you’ve made it this far, you’ve learned how to tell Kubernetes <em>what to do</em>. However, the power of Kubernetes is in its declarative API and controllers. You can just tell Kubernetes <em>what you want</em>, and it will know what to do. So, except for the read-only get, describe and logs, the debugging port-forward, exec and cp, and delete (it’s easier to replace Pods than fix them), you will rarely, if ever, use the other commands that we saw in the previous section (sorry, but they were useful to introduce you to some important concepts). Most of the time, you’ll just use kubectl apply and YAML (or JSON) manifests of the state to be saved by Kubernetes in etcd.</p><p>To scaffold manifests from running objects, you can simply save the output of kubectl get -o yaml --export:</p><pre>kubectl get deployment myapp -o yaml --export &gt; myapp-deployment.yaml<br>kubectl get service myapp -o yaml --export &gt; myapp-service.yaml<br># replicasets and pods are controlled and don’t need manifests (the deployment spec contains a pod template)</pre><p>A manifest actually doesn’t need all of the saved state. Some of it is added by Kubernetes. The--export option removes the status section and some metadata (UID, creation timestamp, etc.), but you may want to remove even more, e.g., default values. We just need enough to specify what we want.</p><p>The documentation provides basic examples for <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment">Deployments</a> and <a href="https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service">Services</a>. In our case, the manifests boil down to this:</p><pre># myapp-deployment.yaml</pre><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: myapp<br>spec:<br>  replicas: 3<br>  selector:<br>    matchLabels:<br>      run: myapp<br>  template:<br>    metadata:<br>      labels:<br>        run: myapp<br>    spec:<br>      containers:<br>      - name: myapp<br>        image: psdocker/myapp:mytag<br>        env:<br>        - name: WHOAMI<br>          value: &quot;HAL 9000&quot;</pre><pre># myapp-service.yaml</pre><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: myapp<br>spec:<br>  selector:<br>    run: myapp<br>  ports:<br>  - port: 80<br>    targetPort: 3000</pre><p>To prove that they work, let’s delete everything first, then apply our manifests:</p><pre>kubectl delete deployment myapp<br>kubectl delete service myapp<br>kubectl apply -f myapp-deployment.yaml -f myapp-service.yaml</pre><p>If we hadn’t deleted the Deployment and Service, they would have been updated to match the manifests. The kubectl apply command is idempotent. We can reuse it after modifying the manifests. For example, try editing the number of replicas and re-run the last command.</p><p>If you’re unsure about the schema or you’d like to explore your options, the Kubernetes <a href="https://kubernetes.io/docs/reference/#api-reference">API reference</a> is a useful companion.</p><p>For complex applications, with several environments, raw manifests can become difficult to manage. Tools like <a href="https://github.com/kubernetes-sigs/kustomize">kustomize</a> (now part of kubectl since v1.14), <a href="https://helm.sh/">Helm</a>, or <a href="https://jsonnet.org/">Jsonnet</a> can help. <a href="https://blog.argoproj.io/the-state-of-kubernetes-configuration-management-d8b06c1205">Jesse Suen wrote a great comparison</a>. To oversee the entire build and deploy process, and inject tagged image names into manifests, <a href="https://github.com/GoogleContainerTools/skaffold">skaffold</a> is another useful tool.</p><h3>Going Further</h3><p>In this tutorial, we’ve worked with the basic building blocks of stateless apps on Kubernetes: Deployments, ReplicaSets, Pods, Services. There are alternatives to Deployments (not all apps support rolling updates): StatefulSets, DaemonSets, Jobs, CronJobs, etc. ConfigMaps and Secrets are useful to store application configuration. Also, we’ve only used Deployments in the most basic manner. In production, you should set CPU and memory requests and limits, and you may be interested in autoscaling, among other things.</p><p>There are a few good books to learn Kubernetes. The only one I’ve read and don’t hesitate to recommend is <a href="https://www.manning.com/books/kubernetes-in-action">Kubernetes in Action</a> (Manning). Of course, the <a href="https://kubernetes.io/docs">official documentation</a> is a great reference and rightly appears at the top of most Google searches.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4be66c5d8914" width="1" height="1" alt=""><hr><p><a href="https://medium.com/payscale-tech/imperative-vs-declarative-a-kubernetes-tutorial-4be66c5d8914">Imperative vs. Declarative — a Kubernetes Tutorial</a> was originally published in <a href="https://medium.com/payscale-tech">PayScale Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>