How to expose my pod to the internet and get to it from the browser?

4/14/2016

first of all I downloaded kubernetes, kubectl and created a cluster from aws (export KUBERNETES_PROVIDER=aws; wget -q -O - https://get.k8s.io | bash )

I added some lines to my project circle.yml to use circleCI services to build my image.

To support docker I added:

machine:
  services:
    - docker

and to create my image and send it to my artifacts I added:

deployment:
    commands:
      - docker login -e admin@comp.com -u ${ARTUSER} -p ${ARTKEY} docker-docker-local.someartifactory.com
      - sbt -DBUILD_NUMBER="${CIRCLE_BUILD_NUM}" docker:publish

After that I created a 2 folders:

my project (MyApp) folder with two files:

controller.yaml

apiVersion: v1
kind: ReplicationController
metadata:
  name: MyApp
  labels:
    name: MyApp
spec:
  replicas: 1
  selector:
    name: MyApp
  template:
    metadata:
      labels:
        name: MyApp
        version: 0.1.4
    spec:
      containers:
      - name: MyApp
        #this is the image artifactory
        image: docker-docker-release.someartifactory.com/MyApp:0.1.4
        ports:
        - containerPort: 9000
      imagePullSecrets:
        - name: myCompany-artifactory

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: MyApp
  labels:
    name: MyApp
spec:
  # if your cluster supports it, uncomment the following to automatically create
  # an external load-balanced IP for the frontend service.
  type: LoadBalancer
  ports:
    # the port that this service should serve on
  - port: 9000
  selector:
    name: MyApp

And I have another folder for my artifactory (Kind : Secret).

Now I created my pods with:

kubectl create -f controller.yaml

And now I have my pod running when I check in kubectl get pods.

Now, how do I access my pod from the browser? my project is a play project so I want to get to it from the browser...how do I expose it the simplest way?

thanks

-- JohnBigs
amazon-web-services
cluster-computing
docker
kubernetes

1 Answer

5/2/2016
  • The Replication Controller sole responsibility is ensuring that the amount of pods with the given configuration are run on your cluster.

  • The Service is what is public (or internally) exposing your pods to other parts of the system (or the internet).

You should create your service with your yaml file (kubectl create -f service.yaml) which will create the service, selecting pods by the label selector MyApp for handling the load on the given port in your file (9000).

Afterwards look at the registered service with kubectl get service to see which endpoint (ip) is allocated for it.

-- Mark van Straten
Source: StackOverflow