<p>I have gotten multiple containers to work in the same pod.</p>

<pre><code> kubectl apply  -f myymlpod.yml

kubectl expose pod mypod --name=myname-pod --port 8855 --type=NodePort
</code></pre>

<p>then I was able to test the "expose"</p>

<pre><code>minikube service list
</code></pre>

<p>..</p>

<pre><code>|-------------|-------------------------|-----------------------------|
|  NAMESPACE  |          NAME           |             URL             |
|-------------|-------------------------|-----------------------------|
| default     | kubernetes              | No node port                |
| default     | myname-pod              | http://192.168.99.100:30036 |
| kube-system | kube-dns                | No node port                |
| kube-system | kubernetes-dashboard    | No node port                |
|-------------|-------------------------|-----------------------------|
</code></pre>

<p>Now, my myymlpod.yml has multiple containers in it.
One container has a service running on 8855, and one on 8877.</p>

<p>The below article ~hints~ at what I need to do .</p>

<p><a href="https://www.mirantis.com/blog/multi-container-pods-and-container-communication-in-kubernetes/" rel="nofollow noreferrer">https://www.mirantis.com/blog/multi-container-pods-and-container-communication-in-kubernetes/</a></p>

<blockquote>
  <h2>Exposing multiple containers in a Pod</h2>
  
  <p>While this example shows how to
  use a single container to access other containers in the pod, it’s
  quite common for several containers in a Pod to listen on different
  ports — all of which need to be exposed. To make this happen, you can
  either create a single service with multiple exposed ports, or you can
  create a single service for every poirt you’re trying to expose.</p>
</blockquote>

<p>"create a single service with multiple exposed ports"</p>

<p>I cannot find anything on how to actually do this, expose multiple ports.</p>

<p>How does one expose multiple ports on a single service?</p>

<p>Thank you.</p>

<p>APPEND:</p>

<p>K8Containers.yml (below)</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: mypodkindmetadataname
  labels:
    example: mylabelname

spec:

  containers:

  - name: containername-springbootfrontend
    image: mydocker.com/webfrontendspringboot:latest 
    resources:
      limits:
        memory: "800Mi"
        cpu: "800m" 
      requests:
        memory: "612Mi"
        cpu: "400m"
    ports:
      - containerPort: 8877


  - name: containername-businessservicesspringboot
    image: mydocker.com/businessservicesspringboot:latest
    resources:
      limits:
        memory: "800Mi"
        cpu: "800m" 
      requests:
        memory: "613Mi"
        cpu: "400m" 
    ports:
      - containerPort: 8855
</code></pre>

<hr>

<pre><code>kubectl apply  -f K8containers.yml
pod "mypodkindmetadataname" created

kubectl get pods
NAME                    READY     STATUS    RESTARTS   AGE
mypodkindmetadataname   2/2       Running   0          11s
</code></pre>

<hr>

<p>k8services.yml (below)</p>

<pre><code>apiVersion: v1
kind: Service
metadata: 
  name: myymlservice
  labels: 
    name: myservicemetadatalabel
spec: 
  type: NodePort
  ports:
  - name: myrestservice-servicekind-port-name
    port: 8857
    targetPort: 8855
  - name: myfrontend-servicekind-port-name
    port: 8879
    targetPort: 8877
  selector: 
    name: mypodkindmetadataname
</code></pre>

<p>........</p>

<pre><code>kubectl apply  -f K8services.yml
service "myymlservice" created
</code></pre>

<p>........</p>

<pre><code> minikube service myymlservice --url
http://192.168.99.100:30784
http://192.168.99.100:31751
</code></pre>

<p>........</p>

<pre><code> kubectl describe service myymlservice


Name:                     myymlservice
Namespace:                default
Labels:                   name=myservicemetadatalabel
Annotations:              kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"name":"myservicemetadatalabel"},"name":"myymlservice","namespace":"default"...
Selector:                 name=mypodkindmetadataname
Type:                     NodePort
IP:                       10.107.75.205
Port:                     myrestservice-servicekind-port-name  8857/TCP
TargetPort:               8855/TCP
NodePort:                 myrestservice-servicekind-port-name  30784/TCP
Endpoints:                &lt;none&gt;
Port:                     myfrontend-servicekind-port-name  8879/TCP
TargetPort:               8877/TCP
NodePort:                 myfrontend-servicekind-port-name  31751/TCP
Endpoints:                &lt;none&gt;
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>

<p>....</p>

<p>Unfortunately, it is still not working when I try to invoke the "exposed" items.</p>

<p>calling</p>

<p><a href="http://192.168.99.100:30784/myrestmethod" rel="nofollow noreferrer">http://192.168.99.100:30784/myrestmethod</a></p>

<p>does not work</p>

<p>and calling</p>

<p><a href="http://192.168.99.100:31751" rel="nofollow noreferrer">http://192.168.99.100:31751</a></p>

<p>or</p>

<p><a href="http://192.168.99.100:31751/index.html" rel="nofollow noreferrer">http://192.168.99.100:31751/index.html</a></p>

<p>does not work</p>

<p>Anyone see what I'm missing.</p>

<p>APPEND (working now)</p>

<p>The selector does not match on "name", it matches on label(s).</p>

<p>k8containers.yml (partial at the top)</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: mypodkindmetadataname
  labels:
    myexamplelabelone: mylabelonevalue
    myexamplelabeltwo: mylabeltwovalue

spec:

  containers:

  # Main application container
  - name: containername-springbootfrontend
    image: mydocker.com/webfrontendspringboot:latest 
    resources:
      limits:
        memory: "800Mi"
        cpu: "800m" 
      requests:
        memory: "612Mi"
        cpu: "400m"
    ports:
      - containerPort: 8877


  - name: containername-businessservicesspringboot
    image: mydocker.com/businessservicesspringboot:latest
    resources:
      limits:
        memory: "800Mi"
        cpu: "800m" 
      requests:
        memory: "613Mi"
        cpu: "400m" 
    ports:
      - containerPort: 8855
</code></pre>

<p>k8services.yml</p>

<pre><code>apiVersion: v1
kind: Service
metadata: 
  name: myymlservice
  labels: 
    name: myservicemetadatalabel
spec: 
  type: NodePort
  ports:
  - name: myrestservice-servicekind-port-name
    port: 8857
    targetPort: 8855
  - name: myfrontend-servicekind-port-name
    port: 8879
    targetPort: 8877
  selector: 
    myexamplelabelone: mylabelonevalue
    myexamplelabeltwo: mylabeltwovalue
</code></pre>

<p>Yes you can create one single service with multiple ports open or service port connect pointing to container ports. </p>

<pre><code>kind: Service
apiVersion: v1
metadata:
  name: mymlservice
spec:
  selector:
    app: mymlapp
  ports:
  - name: servicename-1
    port: 4444
    targetPort: 8855
  - name: servicename-2
    port: 80
    targetPort: 8877
</code></pre>

<p>Where target ports are poting out to your container ports.</p>
