Search code examples
kubernetesgoogle-cloud-platformgoogle-compute-enginekubectlkubeadm

Change kubeadm init ip address


How to change ip when I run kubeadm init? I create master node on google compute engine and want to connect node from aws and azure, but kubeadm use internal ip address which see only from google cloud platform network. I tried to use --apiserver-advertise-address=external ip, but in this case kubeadm stuck in [init] This might take a minute or longer if the control plane images have to be pulled. Firewall are open.


Solution

  • If I understand correctly what you are trying to do is using a GCP instance running kubeadm as the master and two nodes located on two other clouds.

    What you need for this to work is to have a working load balancer with external IP pointing to your instance and forwarding the TCP packets back and forth.

    First I created a static external IP address for my instance:

     gcloud compute addresses create myexternalip --region us-east1
    

    Then I created a a target pool for the LB and added the instance :

    gcloud compute target-pools create kubernetes --region us-east1
    gcloud compute target-pools add-instances kubernetes --instances kubeadm --instances-zone us-east1-b
    

    Add a forwarding rule serving on behalf of an external IP and port range that points to your target pool. You'll have to do this for the ports the nodes need to contact your kubeadm instance on. Use the external IP created before.

    gcloud compute forwarding-rules create kubernetes-forward --address myexternalip --region us-east1 --ports 22 --target-pool kubernetes
    

    You can check now your forwarding rule which will look something like this:

    gcloud compute forwarding-rules describe kubernetes-forward
    IPAddress: 35.196.X.X
    IPProtocol: TCP
    creationTimestamp: '2018-02-23T03:25:49.810-08:00'
    description: ''
    id: 'XXXXX'
    kind: compute#forwardingRule
    loadBalancingScheme: EXTERNAL
    name: kubernetes-forward
    portRange: 80-80
    region: https://www.googleapis.com/compute/v1/projects/XXXX/regions/us-east1
    selfLink: https://www.googleapis.com/compute/v1/projects/XXXXX/regions/us-east1/forwardingRules/kubernetes-forward
    target: https://www.googleapis.com/compute/v1/projects/XXXXX/regions/us-east1/targetPools/kubernetes
    

    Now you can go with the usual process to install kubeadm and set up your cluster in your instance kubeadm init took around 50 seconds on mine.

    Afterwards if you got the ports correctly opened in your firewall and forwarded to your master the nodes from AWS and Azure should be able to join.

    Congratulations, now you have a multicloud kubernetes cluster! :)