PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, December 29, 2021

[FIXED] Use External IP in Google cloud with Kubernetes service to expose it to the internet

 December 29, 2021     google-cloud-platform, kubernetes, phpmyadmin, static-ip-address     No comments   

Issue

I have a phpmyadmin service running on kubernetes cluster. I want to reserve an External IP (static) on google cloud to use with this service so that it could be reachable from the internet. I have tried reserving an IP address on GCP and used it in the kubernetes service file as below:

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert
    kompose.version: 1.21.0 (992df58d8)
  creationTimestamp: null
  labels:
    io.kompose.service: phpmyadmin
  name: phpmyadmin
spec:
  externalIPs: [xx.xxx.xxx.xxx]  #the external IP from Google cloud
  ports:
  - name: "8080"
    port: 8080
    targetPort: 80
  selector:
    io.kompose.service: phpmyadmin
status:
  loadBalancer: {}

When I specify the spec.type: LoadBalancer then the service is accessible from the internet with the default IP address that is generated from the type: LoadBalancer .

I tried to change firewall rules for the External IP address by allowing Ingress on port 8080, but that did not work.


Solution

Instead of setting the exteranlIPs, you should set the spec.loadBalancerIP with the spec.type being of LoadBalancer value:

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert
    kompose.version: 1.21.0 (992df58d8)
  creationTimestamp: null
  labels:
    io.kompose.service: phpmyadmin
  name: phpmyadmin
spec:
  ports:
  - name: "8080"
    port: 8080
    targetPort: 80
  selector:
    io.kompose.service: phpmyadmin
  type: LoadBalancer
  loadBalancerIP: "YOUR_IP_ADDRESS"
status:
  loadBalancer: {}

Note that exposing your Pods through an external static IP only supports regional load balanced traffic hence your reserved static IP address needs to be regional.

For a global IP address, you need to expose a HTTP(s) Load Balancer through an Ingress object.



Answered By - tmarwen
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing