Create kubernetes that manages pods in java

0 votes

I am looking to create a Service that manages a pod with a certain label on a certain port. Can you give me some example because i'm sure there is a way to do this.

Sep 5, 2018 in Kubernetes by Hannah
• 18,570 points
395 views

1 answer to this question.

0 votes

Fabric8's Kubernetes Client is using a generated model and DSL that has the exact same structure as as the JSON and YAML configuration.

So in order to create a Service instance that looks like:

 {
   "kind": "Service",
   "apiVersion": "v1",
   "metadata": {
       "name": "myservice"
   },
   "spec": {
       "ports": [
           {
              "protocol": "TCP",
              "port": 80,
              "targetPort": 8080,
          }
      ],
      "selector": {
          "key": "value1",
      },¬
      "portalIP": "172.30.234.134",
      "type": "ClusterIP",
  }

}

You can use the following code:

Service service = new ServiceBuilder()
          .withNewMetadata()
              .withName("myservice")
          .endMetadata()
          .withNewSpec()
            .addNewPort()
              .withProtocol("TCP")
              .withPort(80)
              .withNewTargetPort(8080)
            .endPort()
            .addToSelector("key1", "value1")
            .withPortalIP("172.30.234.134")
            .withType("ClusterIP")
          .endSpec()
          .build();

If don't need to hold a reference of the service object and you just want to create it, you can inline it like:

client.services().createNew()
          .withNewMetadata()
              .withName("myservice")
          .endMetadata()
          .withNewSpec()
            .addNewPort()
              .withProtocol("TCP")
              .withPort(80)
              .withNewTargetPort(8080)
            .endPort()
            .addToSelector("key1", "value1")
            .withPortalIP("172.30.234.134")
            .withType("ClusterIP")
          .endSpec()
          .done();

answered Sep 5, 2018 by Kalgi
• 52,360 points

Related Questions In Kubernetes

0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
14,662 views
+4 votes
1 answer

Installing Web UI (Dashboard):kubernetes-dashboard on main Ubuntu 16.04.6 LTS (Xenial Xerus) server

Follow these steps: $ kubeadm reset $ kubeadm init ...READ MORE

answered Apr 12, 2019 in Kubernetes by Kalgi
• 52,360 points

reshown Apr 12, 2019 by Kalgi 6,167 views
0 votes
2 answers
0 votes
2 answers

Restart pods when configmap updates in Kubernetes?

Use Deployments, and consider your ConfigMaps to ...READ MORE

answered Aug 31, 2018 in Kubernetes by Nilesh
• 7,050 points
7,355 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP