简体   繁体   中英

How can I get the cluster IP info within the Kubernetes yaml file before it's been created?

I have a docker container that needs to run in Kubernetes, but within its parameters, there's one need the container's Cluster IP info. How can I write a Kubernetes yaml file with that info?

# I want docker to run like this
docker run ... --wsrep-node-address=<ClusterIP>

# xxx.yaml
apiVersion: v1
kind: Pod
metadata:
  name: galera01
  labels:
    name: galera01
  namespace: cloudstack
spec:
  containers:
  - name: galeranode01
    image: erkules/galera:basic
    args:
    # Is there any variable that I can use to represent the
    # POD IP or CLUSTER IP here?
    - --wsrep-node-address=<ClusterIP>

If i get this right you want to know node ip for which runs the container.
You can achive this by using kubernetes dns.
https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/

Services
A records “Normal” (not headless)
Services are assigned a DNS A record for a name of the form my-svc.my-namespace.svc.cluster.local . This resolves to the cluster IP of the Service.


Another way you can create a service and use this.
https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/#accessing-the-service

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM