Expose container on predefined port via Kubernetes in GCloud

7/15/2017

mates

At the moment I'm struggling to expose wordpress docker container on 80 port to be available externally.

What I've done so far:

  1. Deployed wordpress image through kubectl run.
  2. Exposed it as a service.
  3. Added firewall rules to allow ingress traffic.

The kubernetes resources look like the below:

NAME                            READY     STATUS    RESTARTS   AGE       IP           NODE
po/wordpress-3559545868-gz2sl   1/1       Running   0          5h        10.32.0.15   gke-easycoin-default-pool-9f4cab46-69ks

NAME             CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE       SELECTOR
svc/wordpress    10.35.240.122   146.148.17.124   80:30760/TCP     1h        run=wordpress

NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE       CONTAINER(S)   IMAGE(S)                                   SELECTOR
deploy/wordpress   1         1         1            1           5h        wordpress      gcr.io/easy-coin-fund/easycoin-wordpress   run=wordpress

NAME                      DESIRED   CURRENT   READY     AGE       CONTAINER(S)   IMAGE(S)                                   SELECTOR
rs/wordpress-3559545868   1         1         1         5h        wordpress      gcr.io/easy-coin-fund/easycoin-wordpress   pod-template-hash=3559545868,run=wordpress

So far I was able to access my wordpress deployment only through external IP and --type=NodePort which gives me a random one, 30760 in this case.

QUESTION: What parts am I missing to expose the deployment externally directly on the 80 port?

Thanks in advance guys.

Below is the kubernetes description of the resources.

WORDPRESS POD

Name:       wordpress-3559545868-gz2sl
Namespace:  default
Node:       gke-easycoin-default-pool-9f4cab46-69ks/10.132.0.2
Start Time: Sat, 15 Jul 2017 15:29:19 +0300
Labels:     pod-template-hash=3559545868
        run=wordpress
Annotations:    kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"default","name":"wordpress-3559545868","uid":"397b208f-6959-11e7-89f3-42010a84020...
        kubernetes.io/limit-ranger=LimitRanger plugin set: cpu request for container wordpress
Status:     Running
IP:     10.32.0.15
Created By: ReplicaSet/wordpress-3559545868
Controlled By:  ReplicaSet/wordpress-3559545868
Containers:
  wordpress:
    Container ID:   docker://3cf99561402e8a5e7ff7165764bdd6471a959ccd79b41a5197225b0eecaa696f
    Image:      gcr.io/easy-coin-fund/easycoin-wordpress
    Image ID:       docker://sha256:fcb67315d99b058248150d9bac6b25fb24948b45ff1e8c5796174293e19fc6a8
    Port:       80/TCP
    State:      Running
      Started:      Sat, 15 Jul 2017 15:29:41 +0300
    Ready:      True
    Restart Count:  0
    Requests:
      cpu:  100m
    Environment:
      WORDPRESS_DB_HOST:    146.148.17.124:32711
      WORDPRESS_DB_PASSWORD:    cantcrackitblyat
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-d1gdv (ro)
Conditions:
  Type      Status
  Initialized   True 
  Ready     True 
  PodScheduled  True 
Volumes:
  default-token-d1gdv:
    Type:   Secret (a volume populated by a Secret)
    SecretName: default-token-d1gdv
    Optional:   false
QoS Class:  Burstable
Node-Selectors: <none>
Tolerations:    node.alpha.kubernetes.io/notReady:NoExecute for 300s
        node.alpha.kubernetes.io/unreachable:NoExecute for 300s
Events:     <none>

WORDPRESS SERVICE

Name:           wordpress
Namespace:      default
Labels:         run=wordpress
Annotations:        <none>
Selector:       run=wordpress
Type:           NodePort
IP:         10.35.240.122
External IPs:       146.148.17.124
Port:           <unset> 80/TCP
NodePort:       <unset> 30760/TCP
Endpoints:      10.32.0.15:80
Session Affinity:   None
Events:         <none>
-- OneMoreVladimir
docker
gcloud
kubernetes

1 Answer

7/17/2017

Did you try to follow this official tutorial? It explains step by step what you try to achieve.

This service should fix your problem:

apiVersion: v1
kind: Service
metadata:
  labels:
    run: wordpress
  name: wordpress
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  selector:
    run: wordpress
-- Kévin Dunglas
Source: StackOverflow