accessing services outside kubernetes

3/28/2017

I want to access external services/APIs

like calling wikipedia so I need port 80 http://en.wikipedia.org/w/api.php?action=opensearch&search=bee&limit=1&format=json

my app is in a pod inside a container and I exposed port 8000 and binded it 300 in the service type loadbalncer .

Also accessing external databases hosted outside kubernetes like mysql so I need port 3306 how that can be done .

those are both the deployment and service files

https://github.com/hadyrashwan/request-wiki/blob/feature/open-internal-80/wiki-request-deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: request-wiki-deployment
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: request-wiki
    spec:
      containers:
      - name: request-wiki
        image: hadyrashwan/request-wiki:0.0.4
        imagePullPolicy: Always
        ports:
        - containerPort: 8000
        - containerPort: 80

https://github.com/hadyrashwan/request-wiki/blob/feature/open-internal-80/wiki-request-service.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    name: request-wiki
  name:  request-wiki-service
spec:
  selector:
    app: request-wiki
  ports:
#  - name: app
  - port: 3000
    protocol: TCP
    targetPort: 8000
#  - name: app
#    protocol: TCP
#    targetPort: 80
  type: LoadBalancer

still not using configurations/secrets or tls

I'm using rancher with 2 hosts for kubernetes environment one on GCP and the other on AWS

-- Hady Rashwan
docker
kubernetes
mysql
rancher

2 Answers

3/29/2017

By default, your pods will use the docker bridge of the node they are located in for egress connections.

Try to test connections from the nodes you are going to use to deploy your pods, if you can connect from the nodes, your pods should be able to do it too. This way you will be able to track any issue related to egress connections easily (check firewall rules, interfaces configured correctly, etc.).

These port options you are configuring in your yamls are for ingress traffic only.

-- aespejel
Source: StackOverflow

3/28/2017

If I am not wrong then you want to reach your kube service's from outside of kubernetes. You can use service type NodePort

Type NodePort

master will allocate a port from a flag-configured range (default: 30000-32767), and each Node will proxy that port (the same port number on every Node) into your Service. That port will be reported in your Service’s spec.ports[*].nodePort field.If you set the type field to "NodePort", the Kubernetes

you can define kube service like this

{
    "kind": "Service",
    "apiVersion": "v1",
    "metadata": {
        "name": "my-service"
    },
    "spec": {
        "selector": {
            "app": "MyApp"
        },
        "ports": [
            {
                "protocol": "TCP",
                "port": 80,
                "targetPort": 9376,
                "nodePort": 30061
            }
        ],
        "type": "LoadBalancer"
    },
    }
}

Or you can use kubectl as well

kubectl expose rc example-rc --type=NodePort --port=9000 --target-port=8080 --node-port=32001

above should work with deployment as well

so at the end if you want to reach your service then hit anynode:nodeport

-- Deepak
Source: StackOverflow