<p>While trying to install Kubernetes on nixos, using the following stanza:</p>

<pre><code>services.kubernetes.masterAddress = "XXXXXX";
users.users.XXXXXX.extraGroups = [ "kubernetes" ];

services.kubernetes = {
  roles = ["master" "node"];
};
</code></pre>

<p>I hit the following issue:</p>

<pre><code>open /var/lib/kubernetes/secrets/etcd.pem: no such file or directory
</code></pre>

<p>I recognize this as a TLS/SSL certificate, but how should I go about generating that file?</p>

<p>The article you used is really old. It was published <code>2017-07-21</code> so almost 2,5 years ago. You can be pretty sure it's outdated in one way or another however major <strong><em>NixOS</em></strong> <em>approach to setting up kubernetes cluster</em> from end user perspective may have not changed a lot during this time.</p>

<p>So, after familiarizing with it a bit more... I see that this is actually yet another approach to <strong>installing kubernetes cluster</strong> and it has nothing to do with "the hard way" I mentioned in my previous comment. On the contrary, it's the easiest kubernetes cluster setup I've ever seen. Actually you don't have to do anything but add a single entry in your <code>configuration.nix</code> and then run <code>nixos-rebuild switch</code> and you can expect everything to be up and running. But there is really a lot, not just a few things that NixOS takes care about "under the hood". Generating proper certificates is just one of many steps involved in kubernetes cluster setup. Keep in mind that Kubernetes installation from scratch is pretty complex task. Take a brief look at <a href="https://github.com/kelseyhightower/kubernetes-the-hard-way" rel="nofollow noreferrer">this</a> article and you'll see what I mean. This is really amazing thing for educational purposes as there is probably no better way to understand something in-deep, than to build it from scratch, in the possibly most manual way.</p>

<p>On the other hand, if you just need to set up relatively quickly a working kubernetes cluster, Kubernetes the Hard Way won't be your choice. Fortunatelly there are a few solutions that give you possibility to set up your kubernetes cluster relatively quickly and simply.</p>

<p>One of them is <a href="https://kubernetes.io/docs/setup/learning-environment/minikube/" rel="nofollow noreferrer">Minikube</a>.
The other one which gives you possibility to set-up multi-node kubernetes cluster is <a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/" rel="nofollow noreferrer">kubeadm</a>.</p>

<p>Going back to <strong>NixOS</strong>, I'm really impressed by how simple it is to set up your kubernetes cluster on this system, provided everything works as expected. But what if it doesn't ( and this is mainly what your question was about ) ? You may try to debug it on your own and try to look for a workaround of your issue or simply create an issue on <strong>NixOS project</strong> <a href="https://github.com/NixOS" rel="nofollow noreferrer">github page</a> like <a href="https://github.com/NixOS/nixpkgs/issues/59364" rel="nofollow noreferrer">this one</a>. As you can see someone already reported exactly the same problem as yours. They say that on the 18.09 release it works properly so probably you're using newer version like 19.03. You can further read that there were some major changes like moving to mandatory pki in 19.03.</p>

<p>Take a closer look at this issue if you're particularly interested in <strong>running kubernetes on NixOS</strong> as there are a few advices and workarounds described there:</p>

<p><a href="https://github.com/NixOS/nixpkgs/issues/59364#issuecomment-485122860" rel="nofollow noreferrer">https://github.com/NixOS/nixpkgs/issues/59364#issuecomment-485122860</a>
<a href="https://github.com/NixOS/nixpkgs/issues/59364#issuecomment-485249797" rel="nofollow noreferrer">https://github.com/NixOS/nixpkgs/issues/59364#issuecomment-485249797</a></p>

<p>First of all make sure that your <code>masterAddress</code> is set properly i.e. as hostname, not ip address. As you put there only <code>"XXXXXX"</code> I can't guess what is currently set there. It's quite likely that when you set it e.g. to <code>localhost</code>, appropriate certificate would be generated properly:</p>

<pre><code>services.kubernetes = {
   roles = ["master"];
   masterAddress = "localhost";
  };
</code></pre>

<p>You may also want to familiarize with <a href="https://nixos.org/nixos/manual/index.html#sec-kubernetes" rel="nofollow noreferrer">this</a> info in <strong>NixOS</strong> docs related with <strong>Kubernetes</strong>.</p>

<p>Let me know if it helped.</p>
