Converting docker run to YAML for Kubernetes

6/22/2020

I'm new to Kubernetes. I'm trying to convert the following DOCKER container code to YAML for kubernetes.

docker container run -d -p 80:80 --name MyFirstContainerWeb docker/getting-started:pwd

This is what I have come up with so far. Can someone please help me with the ingress part? I'm using Docker Desktop (which has kubernetes cluster). My final goal is to see the website in the browser.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: getting-started-deployment 
spec:
  selector:
    matchLabels:
      app: getting-started 
  replicas: 2
  template:
    metadata:
      labels:
        app: getting-started
    spec:
      containers:
      - name: getting-started-container 
        image: docker/getting-started:pwd
        ports:
        - containerPort: 80
---
 apiVersion: v1
 kind: Service
 metadata:
   name: getting-started-service 
   namespace: default
   labels:
     app: myfirstcontainer
 spec:
   ports:
   - protocol: TCP
     port: 80
     targetPort: 80
   selector:
     app: getting-started-service
-- RaviLobo
kubernetes
yaml

1 Answer

6/22/2020

You can use port-forward to forward to service port by running

$ kubectl port-forward svc/getting-started-service 80

To learn more about port-forwarding click here

-- hoque
Source: StackOverflow