<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Chris Heppell</title>
    <description>The latest articles on DEV Community by Chris Heppell (@cjheppell).</description>
    <link>https://dev.to/cjheppell</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F358997%2F26eccafd-c341-4f0c-8de4-c83529399bb2.jpg</url>
      <title>DEV Community: Chris Heppell</title>
      <link>https://dev.to/cjheppell</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cjheppell"/>
    <language>en</language>
    <item>
      <title>Next.js development with instant dev-database provisioning</title>
      <dc:creator>Chris Heppell</dc:creator>
      <pubDate>Mon, 05 Oct 2020 09:39:54 +0000</pubDate>
      <link>https://dev.to/cjheppell/next-js-development-with-instant-dev-database-provisioning-561p</link>
      <guid>https://dev.to/cjheppell/next-js-development-with-instant-dev-database-provisioning-561p</guid>
      <description>&lt;p&gt;&lt;a href="https://nextjs.org/"&gt;Next.js&lt;/a&gt; is a really exciting framework that makes it simple to build React applications with excellent features that you’d expect in production. I won’t go into much detail here, as the &lt;a href="https://nextjs.org/"&gt;Next.js documentation does that brilliantly&lt;/a&gt;, but one of the key things that stood out is the &lt;strong&gt;easy development experience&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;By using &lt;a href="https://github.com/vercel/next.js/tree/canary/packages/create-next-app"&gt;create-next-app&lt;/a&gt; you can immediately get set up with an interactive dev experience that auto-reloads code changes in your browser as you make changes. Next.js also has support for building web APIs without needing any separate API server (e.g, &lt;a href="https://dotnet.microsoft.com/apps/aspnet"&gt;ASP.NET Core&lt;/a&gt;, &lt;a href="https://golang.org/pkg/net/http/"&gt;Go’s net/http package&lt;/a&gt;). It can serve your frontend, and handle your API requests all in one.&lt;/p&gt;

&lt;p&gt;But what if your backend API needs to request data from a database? Well, this is easy enough to do via packages like &lt;a href="https://github.com/jeremydaly/serverless-mysql"&gt;&lt;code&gt;serverless-mysql&lt;/code&gt;&lt;/a&gt; that let you initiate connections to a MySQL database from NodeJS. Add the dependency, run your queries in response to an API call in Next.js and then send the results back to the frontend (usually as JSON). Easy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Something is missing…
&lt;/h2&gt;

&lt;p&gt;Next.js itself is great. From a dev perspective it’s easy to get set up instantly with an environment and start coding.&lt;/p&gt;

&lt;p&gt;But when it comes to building an app that requires a backend database, things get a bit more tricky as a developer.&lt;/p&gt;

&lt;p&gt;In production, you’ve likely got some kind of managed database offering (or a DBA) that is responsible for maintaining your database. You get given some connection details and off you go.&lt;/p&gt;

&lt;p&gt;But as a dev who wants to get started actually making changes, you might start to ask yourselves these kinds of questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Should I install the database engine on my machine?&lt;/li&gt;
&lt;li&gt;Should I run it in a Docker container?&lt;/li&gt;
&lt;li&gt;If I run it in Docker, how do I persist my data in the case of container restarts?&lt;/li&gt;
&lt;li&gt;Should I connect to a database instance I share with the rest of the development team?&lt;/li&gt;
&lt;li&gt;What if I need production-like data? Restoring a backup can take a long time…&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’ve set up Next.js but you’ve hit this roadblock, you might be frustrated with how good the development experience was up to this point. Suddenly, you have to worry about maintaining a stateful database alongside your dev environment, and that’s not insignificant.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6bqWafCQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kvd1hkzhprb1nxwmv7wc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6bqWafCQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kvd1hkzhprb1nxwmv7wc.png" alt="Databases can make development environments tricky"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Levelling the playing field
&lt;/h2&gt;

&lt;p&gt;Getting a database environment should be as easy as scaffolding an entire Next.js application. So we set about making that reality.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://spawn.cc/"&gt;Spawn&lt;/a&gt; is a new solution we’re working on that aims to make it really easy to include databases in your dev and CI environments. It removes the uncertainty around &lt;em&gt;how&lt;/em&gt; to get a database environment and instead encourages you to spin them up and down as much as you like, without any concern over infrastructure.&lt;/p&gt;

&lt;p&gt;To really put this into perspective, let’s see how Spawn fits in a Next.js application.&lt;/p&gt;

&lt;p&gt;If you’d like to check out the code I’ll be discussing, you can review the GitHub repository &lt;a href="https://github.com/cjheppell/spawn-with-nextjs"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hooking things up
&lt;/h2&gt;

&lt;p&gt;For the sake of brevity, I followed the tutorial on setting up a &lt;a href="https://vercel.com/guides/deploying-next-and-mysql-with-vercel"&gt;Next.js app with a MySQL Database That Builds and Deploys with Vercel&lt;/a&gt;. This is an excellent tutorial which I encourage you to check out, but we won’t be concerning ourselves with the deployment side for now.&lt;/p&gt;

&lt;p&gt;The real question is how do we spin up that database and hook it up with the API that Next.js makes available to us?&lt;/p&gt;

&lt;p&gt;Well, &lt;a href="https://spawn.cc/"&gt;Spawn&lt;/a&gt; is &lt;strong&gt;entirely commandline driven&lt;/strong&gt;. As such, it’s possible to configure an npm script that runs just before the dev script provided by next.js. This predev script does one thing: create a &lt;a href="https://spawn.cc/docs/concepts-data-container"&gt;Spawn data container&lt;/a&gt; and update the &lt;a href="https://nextjs.org/docs/basic-features/environment-variables#loading-environment-variables"&gt;&lt;code&gt;.env.local&lt;/code&gt;&lt;/a&gt; file with the connection details to be consumed by our API.&lt;/p&gt;

&lt;p&gt;Here’s a snippet of the &lt;code&gt;spawn.sh&lt;/code&gt; script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;containersExist&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; “Spawn data container already provisioned”
&lt;span class="k"&gt;else
    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; “Provisioning Spawn data container &lt;span class="k"&gt;for &lt;/span&gt;dev”
    spawnctl create data-container &lt;span class="nt"&gt;--image&lt;/span&gt; &lt;span class="nv"&gt;$DATA_IMAGE&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
      &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="nv"&gt;$CONTAINER_NAME&lt;/span&gt; &lt;span class="nt"&gt;-q&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; “Spawn data container successfully provisioned”
&lt;span class="k"&gt;fi

&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; “Updating data container connection details &lt;span class="k"&gt;in&lt;/span&gt; .env.local”

&lt;span class="nv"&gt;db_conn_json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;spawnctl get data-container &lt;span class="nv"&gt;$CONTAINER_NAME&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; json&lt;span class="si"&gt;)&lt;/span&gt;

&lt;span class="nv"&gt;DB_HOST&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$db_conn_json&lt;/span&gt; | jq .host&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;DB_PORT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$db_conn_json&lt;/span&gt; | jq .port&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;DB_USERNAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$db_conn_json&lt;/span&gt; | jq .user&lt;span class="si"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;DB_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$db_conn_json&lt;/span&gt; | jq .password&lt;span class="si"&gt;)&lt;/span&gt;

&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt; &amp;gt; .env.local
MYSQL_HOST=&lt;/span&gt;&lt;span class="nv"&gt;$DB_HOST&lt;/span&gt;&lt;span class="sh"&gt;
MYSQL_PORT=&lt;/span&gt;&lt;span class="nv"&gt;$DB_PORT&lt;/span&gt;&lt;span class="sh"&gt;
MYSQL_USERNAME=&lt;/span&gt;&lt;span class="nv"&gt;$DB_USERNAME&lt;/span&gt;&lt;span class="sh"&gt;
MYSQL_PASSWORD=&lt;/span&gt;&lt;span class="nv"&gt;$DB_PASSWORD&lt;/span&gt;&lt;span class="sh"&gt;
MYSQL_DATABASE=nextjs
&lt;/span&gt;&lt;span class="no"&gt;EOF
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As you can see at the end of this, we write the database connection details to the .env.local file. This presumes that I already have a &lt;a href="https://spawn.cc/docs/concepts-data-image"&gt;data image&lt;/a&gt; available (which can be created from SQL Scripts, or the &lt;strong&gt;latest backup from production&lt;/strong&gt; if you care about production-like data) and then creates a data container I can use which is a copy of that data image. This &lt;strong&gt;&lt;a href="https://spawn.cc/docs/concepts-data-container"&gt;data container&lt;/a&gt; is created instantly&lt;/strong&gt; — regardless of the size of the data image.&lt;/p&gt;

&lt;p&gt;There’s absolutely &lt;strong&gt;nothing else for me to do here&lt;/strong&gt;. Instead of needing to install Docker or a database engine on my machine and start it up, wait for connections to be accepted, then figure out the correct connection details to pass through, &lt;strong&gt;all I have to do is ask Spawn to give me a dev database and a few seconds later I’ve got the connection details.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This &lt;em&gt;makes&lt;/em&gt; it much easier to bootstrap an entire dev environment &lt;em&gt;including the database.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_e6Hx9d9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bcnbtoki99gyi1r9c3f6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_e6Hx9d9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bcnbtoki99gyi1r9c3f6.png" alt="Getting up and running with Next.js and Spawn"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The best bit? All of this is committed to source control. After installing the &lt;code&gt;spawnctl&lt;/code&gt;, I can checkout the repository on my machine, run &lt;code&gt;yarn dev&lt;/code&gt; and then I’ve got my Next.js application up and running, backed by an API which can communicate with my database instantly. Onboarding a new dev is as simple as asking them to clone your repo.&lt;/p&gt;

&lt;p&gt;Spawn has a bunch of other benefits, like being able to &lt;a href="https://spawn.cc/docs/spawnctl-dc-save"&gt;&lt;strong&gt;save the state of my database as I work&lt;/strong&gt;&lt;/a&gt; in case I accidentally mess up and delete some data, and I can even make as many save points as I like to create a history of revisions. Equally, &lt;strong&gt;each dev in my team gets their own isolated data container&lt;/strong&gt; for use in development, so I don’t have to worry about sharing a single instance and overwriting others’ changes.&lt;/p&gt;

&lt;p&gt;If you’d like to take a more detailed look at the code to set this up, you can view it in the &lt;a href="https://github.com/cjheppell/spawn-with-nextjs"&gt;GitHub repo&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get Spawn now
&lt;/h2&gt;

&lt;p&gt;We’re currently accepting beta users for Spawn, so if this workflow looks like something you’d be interested in you can &lt;a href="https://spawn.cc/beta"&gt;&lt;strong&gt;sign up to get access here&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>database</category>
      <category>mysql</category>
      <category>development</category>
    </item>
    <item>
      <title>Extending Kubernetes with Operators</title>
      <dc:creator>Chris Heppell</dc:creator>
      <pubDate>Wed, 01 Apr 2020 14:48:30 +0000</pubDate>
      <link>https://dev.to/cjheppell/extending-kubernetes-with-operators-45od</link>
      <guid>https://dev.to/cjheppell/extending-kubernetes-with-operators-45od</guid>
      <description>&lt;p&gt;&lt;em&gt;This article was originally posted to the &lt;a href="https://medium.com/ingeniouslysimple/extending-kubernetes-with-operators-d99c4a02af72"&gt;Ingeniously Simple Medium publication&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Having attended the last two European KubeCon events (2018 and 2019), it’s become increasingly obvious that &lt;strong&gt;operators&lt;/strong&gt; are becoming a hot topic within the community.&lt;/p&gt;

&lt;p&gt;There were zero sessions on operators in 2018, whereas &lt;a href="https://events19.linuxfoundation.org/events/kubecon-cloudnativecon-europe-2019/schedule/"&gt;there were 9 in 2019&lt;/a&gt;. There’s even a dedicated &lt;a href="https://sched.co/MQf3"&gt;OperatorCon&lt;/a&gt; hosted by &lt;a href="https://www.loodse.com/"&gt;Loodse&lt;/a&gt; at this year’s (unfortunately postponed) KubeCon!&lt;/p&gt;

&lt;p&gt;I also had the pleasure of attending the &lt;a href="https://sched.co/MQf3"&gt;Operator Framework Workshop session delivered by Red Hat&lt;/a&gt;. This was an excellent session which covered the basics of Operators and how to create them using the &lt;a href="https://github.com/operator-framework"&gt;Operator Framework&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  So what is an operator?
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://coreos.com/operators/"&gt;CoreOS documentation&lt;/a&gt; does an excellent job of explaining this, so I’ll only try and summarise it here.&lt;/p&gt;

&lt;p&gt;An operator is an application that &lt;strong&gt;runs in Kubernetes, acting upon the presence of Kubernetes Custom Resources based on their definition&lt;/strong&gt;. Typically, you might use an operator to handle the &lt;strong&gt;management&lt;/strong&gt; of &lt;strong&gt;services within Kubernetes&lt;/strong&gt; by &lt;strong&gt;encapsulating the operational knowledge of a given service in code&lt;/strong&gt;. Ultimately, the operator runs as a pod within the cluster (possibly with more supporting pods).&lt;/p&gt;

&lt;p&gt;As an example, take a look at the &lt;a href="https://github.com/zalando/postgres-operator"&gt;Zalando Postgres Operator&lt;/a&gt;. Running databases in Kubernetes can be tricky, since it requires persistent volumes, stateful sets, and services to expose them. Instead, the Zalando Postgres Operator encapsulates all the complexity of this behind a single “custom resource” in the cluster of type “&lt;code&gt;postgresql&lt;/code&gt;”. You can see an example of a &lt;a href="https://github.com/zalando/postgres-operator/blob/master/manifests/minimal-postgres-manifest.yaml"&gt;minimal &lt;code&gt;postgresql&lt;/code&gt; configuration custom resource here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Notice how it defines things such as the users and databases you want in the instance when it starts. Creating the users and databases is possible without an operator &lt;strong&gt;provided that the container image you use supports it&lt;/strong&gt;. If it doesn’t, you’ll need to explore different options for initialising the database after the pod enters a ready state. Furthermore, you’ll have to handle the persistent volumes, statefulsets, and services yourself, including how all of those link up with each other.&lt;/p&gt;

&lt;p&gt;Instead, the operator will create all of these resources for you without you needing to know the details. All you do as a consumer of the operator is create the &lt;code&gt;postgresql&lt;/code&gt; custom resource and submit it to the cluster. The operator will do the rest — creating the associated resources in the cluster for you and performing any post-setup actions you defined. It can also (optionally) do things you already come to expect from Kubernetes such as deployments ensuring the correct number of pod replicas are always available. The details depend on the operator implementation.&lt;/p&gt;

&lt;p&gt;In summary, the operator is effectively giving you a higher level abstraction over Kubernetes from the point of view of running and managing Postgres.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PDJkf3ca--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tefac2zyxslyziuf9gv6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PDJkf3ca--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tefac2zyxslyziuf9gv6.jpg" alt="stacked stones"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Operators add a level on top of the existing Kubernetes API — letting you work at a higher level of abstraction&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How do you build an operator?
&lt;/h2&gt;

&lt;p&gt;Whilst operators are a recognised pattern for building these solutions, there are also some opinionated frameworks that make it easy to get started with creating one.&lt;/p&gt;

&lt;p&gt;The one I’ve had experience with is the &lt;a href="https://github.com/operator-framework/operator-sdk"&gt;&lt;code&gt;operator-sdk&lt;/code&gt;&lt;/a&gt;, which is part of the &lt;a href="https://github.com/operator-framework"&gt;Operator Framework&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This scaffolds all the boilerplate required for creating a Kubernetes Operator. It autogenerates things such as the &lt;strong&gt;custom resource definitions&lt;/strong&gt;, the &lt;strong&gt;controller for consuming those custom resources&lt;/strong&gt;, and all of the plumbing to &lt;strong&gt;communicate with the Kubernetes cluster itself&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/operator-framework/operator-sdk#quick-start"&gt;&lt;code&gt;operator-sdk&lt;/code&gt;&lt;/a&gt; documentation is the best place to understand how to actually generate all these things, so I won’t repeat it here. If you’re looking to build an operator yourself, this is an excellent place to start.&lt;/p&gt;

&lt;h2&gt;
  
  
  How have we used operators?
&lt;/h2&gt;

&lt;p&gt;One of the projects we’re working on at Redgate is &lt;a href="https://spawn.cc/"&gt;Spawn&lt;/a&gt;. The idea of this is to provision databases for dev/test purposes instantly, irrespective of the underlying size of that database. You can also save arbitrary states of the database, instantly reverting destructive changes or jumping between known checkpoints to support and accelerate development.&lt;/p&gt;

&lt;p&gt;We use a combination of different technologies within &lt;a href="https://spawn.cc/"&gt;Spawn&lt;/a&gt;, but one of the key components is the &lt;strong&gt;Spawn Kubernetes Operator&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XjtNzt6T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/r56z2jflbvlpncyqsu8f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XjtNzt6T--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/r56z2jflbvlpncyqsu8f.png" alt="`spawncontainer` Kubernetes Custom Resource Definition (CRD)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;“&lt;code&gt;spawncontainer&lt;/code&gt;” Kubernetes Custom Resource Definition (CRD)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is responsible for provisioning database pods in a Kubernetes cluster according to a &lt;code&gt;spawncontainer&lt;/code&gt; custom resource submitted to the cluster. The &lt;code&gt;spawncontainer&lt;/code&gt; custom resource defines a few things in its specification:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The database engine to provision&lt;/li&gt;
&lt;li&gt;Database engine-specific configuration parameters (e.g, admin credentials)&lt;/li&gt;
&lt;li&gt;The network location of the filesystem to use as the underlying filesystem for the database&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This provides a nice abstraction for provisioning those databases. Typically, you’d have to handle creating a pod, with a mounted persistent volume claim that refers to a persistent volume, and then exposing that pod with a service.&lt;/p&gt;

&lt;p&gt;Instead, the &lt;code&gt;spawncontainer&lt;/code&gt; custom resource is submitted to the cluster with the desired configuration and the Spawn Operator consumes that, constructing and connecting all the necessary underlying Kubernetes primitive resource types. When it comes time to clean up this resource, we don’t have to worry about deleting each individual Kubernetes primitive. We simply delete the &lt;code&gt;spawncontainer&lt;/code&gt; custom resource, which causes a cascade of deletions for all primitive resources that were created as a result.&lt;/p&gt;

&lt;p&gt;This dramatically simplifies things for the supporting services that compose Spawn. They simply request a &lt;code&gt;spawncontainer&lt;/code&gt;, and then at some point a database engine is available configured appropriately. The complexity of Kubernetes is hidden behind this abstraction, and operations are performed on the custom resource directly.&lt;/p&gt;

&lt;p&gt;Building this operator has made developing &lt;a href="https://spawn.cc/"&gt;Spawn&lt;/a&gt; &lt;strong&gt;significantly easier&lt;/strong&gt;. We can take advantage of many of the benefits of Kubernetes without having to undertake constructing hand-crafted requests to the cluster API and figuring out how to watch resources and react to changes. Instead, we rely on the scaffolding from the &lt;strong&gt;&lt;code&gt;operator-sdk&lt;/code&gt;&lt;/strong&gt; and simply concern ourselves with writing the business logic — the piece that constructs and links all the Kubernetes resources together that represent a &lt;code&gt;spawncontainer&lt;/code&gt; custom resource.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Operators are an &lt;strong&gt;excellent&lt;/strong&gt; way to build applications that extend the Kubernetes API with domain-specific knowledge. You can hide the complexities of running a system by putting it behind a custom resource that represents the desired state of the system. Users simply interact with that object, and the important changes are made by the operator which effectively translates the domain specific resource into Kubernetes primitive resources.&lt;/p&gt;

&lt;p&gt;If you’re looking to do this, then I’d recommend checking out the operator-sdk and having a play to see what you can do. If you’re trying to run a service in the cluster, then &lt;a href="https://operatorhub.io/"&gt;operatorhub.io&lt;/a&gt; is a great place to go to see if an operator already exists for managing it.&lt;/p&gt;

&lt;p&gt;Thanks to our operator, we’ve also just launched a closed beta programme for &lt;a href="https://spawn.cc/"&gt;Spawn&lt;/a&gt;. If you’re wanting to accelerate your dev/test workflows with instant isolated copies of large production-like database environments that you can immediately spin up, tear down, checkpoint and reset, then sign up at &lt;a href="http://spawn.cc/beta"&gt;spawn.cc/beta&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can also read more about Spawn &lt;a href="https://medium.com/ingeniouslysimple/accelerating-development-with-instant-production-like-containerised-databases-b502ea760dab"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
