<p>I created a pod with an api and web docker container in kuberneters using a yml file (see below).</p>

<pre><code>apiVersion: v1
kind: Pod
metadata: 
  name: test
  labels:
    purpose: test
spec:
  containers:
  - name: api
    image: gcr.io/test-1/api:latest
    ports:
      - containerPort: 8085
        name: http
        protocol: TCP
  - name: web
    image: gcr.io/test-1/web:latest
    ports:
      - containerPort: 5000
        name: http
        protocol: TCP
</code></pre>

<p>It show my pod is up and running</p>

<pre><code>NAME       READY     STATUS    RESTARTS   AGE
test   2/2       Running   0          5m
</code></pre>

<p>but I don't know how to expose it from here.</p>

<p>it seems odd I would have to run kubectl run .... again as the pod is already running. It does not show a deployment though. </p>

<p>if I try something like </p>

<pre><code>kubectl expose deployment test --type="NodePort"--port 80 --target-port 5000
</code></pre>

<p>it complains about deployments.extensions "test' not found. What is the cleanest way to deploy from here?</p>

<p>To expose a deployment to the public internet, you will want to use a Service. The service type LoadBalancer handles this nicely, as you can just use pod selectors in the yaml file.</p>

<p>So if my deployment.yaml looks like this:</p>

<pre><code>kind: Deployment
apiVersion: apps/v1beta2
metadata:
  name: test-dply
spec:
  selector:
    # Defines the selector that can be matched by a service for this 
deployment
    matchLabels:
       app: test_pod
  template:
    metadata:
      labels:
        # Puts the label on the pod, this must match the matchLabels 
selector
        app: test_pod
    spec:
      # Our containers for training each model
      containers:
      - name: mycontainer
        image: myimage
        imagePullPolicy: Always
        command: ["/bin/bash"]
        ports:
        - name: containerport
          containerPort: 8085
</code></pre>

<p>Then the service that would link to it is:</p>

<pre><code>kind: Service
apiVersion: v1
metadata:
  # Name of our service
  name: prodigy-service
spec:
  # LoadBalancer type to allow external access to multiple ports
  type: LoadBalancer
  selector:
    # Will deliver external traffic to the pod holding each of our containers
    app: test_pod
  ports:
    - name: sentiment
      protocol: TCP
      port: 80
      targetPort: containerport
</code></pre>

<p>You can deploy these two items by using <code>kubectl create -f /path/to/dply.yaml</code> and <code>kubectl create -f /path/to/svc.yaml</code>. Quick note: The service will allocate a public IP address, which you can find using <code>kubectl get services</code> with the following output:</p>

<pre><code>NAME                    TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)                      AGE
carbon-relay            ClusterIP      *.*.*.*    &lt;none&gt;           2003/TCP                     78d
comparison-api          LoadBalancer   *.*.*.*    *.*.*.*     80:30920/TCP                 15d
</code></pre>

<p>It can take several minutes to allocate the ip, just a forewarning. But the LoadBalancer's ip is fixed, and you can delete the pod that it points to and re-spin it without consequence. So if I want to edit my test.dply, I can without worrying about my service being impacted. You should rarely have to spin down services</p>
