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,520 points
586 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,350 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
15,476 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,034 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,060 points
7,632 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