<p>I want to run Kubernetes <code>v1.13.5</code> unit-tests inside a CentOS docker container running on a macOS host. I get errors trying to run <code>kubeadm</code> as it doesn't like having swap enabled.</p>

<p>1) I tried <code>kubeadm init --fail-swap-on=false</code> but get <code>Error: unknown flag: --fail-swap-on</code>.  Maybe only supported in older k8s but docs don't seem clear. </p>

<p>2) I tried 
<code>kubeadm init  --config /etc/kubernetes/kubeadm-config.yaml --ignore-preflight-errors=all --skip-token-print</code>
with <code>/etc/kubernetes/kubeadm-config.yaml</code> like </p>

<pre><code>---
apiVersion: kubeadm.k8s.io/v1alpha3
controlPlaneEndpoint: ""
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: k8s.gcr.io
kind: ClusterConfiguration
networking:
  podSubnet: "10.244.0.0/16"
  serviceSubnet: "10.96.0.0/12"
kubernetesVersion: "v1.13.5"
failSwapOn: false
</code></pre>

<p>but that gives ... <code>error execution phase wait-control-plane: couldn't initialize a Kubernetes cluster", ... SNIP ... error unmarshaling JSON: while decoding JSON: json: unknown field \"failSwapOn\""</code></p>

<p>3) I tried switching off swap inside my container but I get ...</p>

<blockquote>
  <p>docker run -i -t centos<br>
     [root@2ed611b32f1a /]# swapoff -a<br>
     swapoff: Not superuser.</p>
</blockquote>

<p>or it when <code>privileged</code> mode it ran but didn't affect setup  </p>

<pre><code>docker run --privileged -i -t centos 
[root@94f9a0e5e46a /]# swapoff -a
[root@94f9a0e5e46a /]# free -h
              total        used        free      shared  buff/cache   available
Mem:           12Gi       371Mi        11Gi       1.0Mi       1.1Gi        12Gi
Swap:         2.0Gi          0B       2.0Gi
</code></pre>

<p>4) I tried flags like <code>docker run --memory 256M --memory-swap 256M</code> but these are <a href="https://github.com/docker/for-mac/issues/2931" rel="nofollow noreferrer">not honoured inside the container</a> despite <a href="https://docs.docker.com/config/containers/resource_constraints/" rel="nofollow noreferrer">https://docs.docker.com/config/containers/resource_constraints/</a> saying ...</p>

<blockquote>
  <p>PREVENT A CONTAINER FROM USING SWAP</p>
  
  <p>If --memory and --memory-swap are set to the same value, this prevents
  containers from using any swap. This is because --memory-swap is the
  amount of combined memory and swap that can be used, while --memory is
  only the amount of physical memory that can be used.</p>
</blockquote>

<p>5) I tried in docker desktop v2.1.0.3 on my laptop adjusting the swap setting via the preferences in its UI, but it won't let me decrease swap below 512.0 MiB.</p>

<p>Can you advise a way <strong>to get k8s running inside CentOS docker container running on my macOS host</strong> ?</p>

k1eran
<p>I think the problem may be your <code>apiVersion</code> for kubeadm! You have an old deprecated version in there which is <code>v1alpha3</code> It is highly recommended <a href="https://v1-13.docs.kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-init/#config-file" rel="nofollow noreferrer">here</a> that you migrate your old configuration to use the newer api which is <code>v1beta1</code> </p>

<blockquote>
  <p>In Kubernetes 1.11 and later, the default configuration can be printed out using the kubeadm config print command. It is recommended that you migrate your old v1alpha3 configuration to v1beta1 using the kubeadm config migrate command, because v1alpha3 will be removed in Kubernetes 1.14.</p>
</blockquote>
