<p>New to Kubernetes but want to quickly run some Docker containers on different machines, e.g, containers 1, 2 and 3 on node 1 (physical machine 1) and container 4, 5, and 6 on node 2 (physical machine 2). Can someone help me with the config files and commands to get it up and running, and all containers can communicate with each other?</p>

<p>I found the example in <a href="https://gettech1.wordpress.com/2016/10/03/kubernetes-forcefully-run-pod-on-specific-node/" rel="nofollow noreferrer">https://gettech1.wordpress.com/2016/10/03/kubernetes-forcefully-run-pod-on-specific-node/</a> close to what I want, but there is only one pod. How do I do it with two pods (assuming that I can add more containers in each pod) and run the two pods together in one deployment (so that containers are within the same network, therefore, can communicate with each other)?</p>

<p>I also want to run a Docker container with a bind mount with "shared" bind-propagation, how can I specify it?</p>

<p>Personally, I found the Kubernetes documentation a little hard to navigate with layers of concepts referencing each other. Anyone can point to a clean tutorial would be a help too. I'd like to learn how to run containers on multiple machines, then how to autoscale by adding more containers in a pod, adding more pods on a node and adding more nodes in a cluster. Then the different type of networking and volume management.</p>

<p>The simple way to assign <a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/" rel="nofollow noreferrer"><code>Pods</code> to <code>Nodes</code></a> is to use <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors" rel="nofollow noreferrer">label selectors</a>. </p>

<p><a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/" rel="nofollow noreferrer"><code>Labels</code> and <code>Selectors</code></a> are a concept you will need to understand throughout Kubernetes. </p>

<p>First add labels to the nodes:</p>

<pre><code>kubectl local nodes node-a podwants=somefeatureon-nodea
kubectl local nodes node-b podwants=somefeatureon-nodeb
</code></pre>

<p>A <code>nodeSelector</code> can then be set in the Pod definitions <code>spec</code>. </p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: my-app
spec:
  nodeSelector:
    podwants: somefeatureon-nodea
  container:
    - name: nginx
      image: nginx:1.8
      ports:
      - containerPort: 80
</code></pre>

<p>As a <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/" rel="nofollow noreferrer"><code>Pod</code></a> will always be co-located in Kubernetes and containers in the <code>Pod</code> will all be able to access each other, <code>Pod</code> to <code>Pod</code> communication is done via exposing the <code>Pod</code> as a <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer"><code>Service</code></a>. Note the <code>Service</code> also uses a label selector to find it's <code>Pods</code></p>

<pre><code>kind: Service
apiVersion: v1
metadata:
  name: web-svc
spec:
  selector:
    app: my-app
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
</code></pre>

<p>Then you can <a href="https://kubernetes.io/docs/concepts/services-networking/service/#discovering-services" rel="nofollow noreferrer">discover the available <code>Services</code></a> in other <code>Pods</code> via environment variables or via DNS if you have <a href="https://kubernetes.io/docs/concepts/cluster-administration/addons/" rel="nofollow noreferrer">added CoreDNS</a> to your cluster. </p>

<pre><code> WEB_SVC_SERVICE_HOST=x.x.x.x
 WEB_SVC_SERVICE_PORT=80
</code></pre>

<p>You won't often define and schedule <code>Pods</code> themselves. You will probably use a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">Deployment</a> that describes your <code>Pods</code> and will help you scale them. </p>

<p>Once you've got the simple case down the documentation follows on to describe <a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity" rel="nofollow noreferrer">Node affinity</a> which allows you to define more complex rule sets. Even down to the level of making scheduling decisions based on what <code>Pods</code> are currently scheduled on the <code>Node</code>.</p>
