<p>I m trying to create a service where there is a connection between the pods via a service with the <code>spec type: ClusterIP</code>and now I want to expose this application to my browser with the <code>spec type: NodePort</code> However I m not able to add the type NodePort to the existing service.yaml. How do I specify the second specs in the same service for the same application?</p>
<p>app1--&gt;connects to app2(db via ClusterIP: port 1521)
app1--&gt;expose to ingress to access it from my browser</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {&quot;apiVersion&quot;:&quot;v1&quot;,&quot;kind&quot;:&quot;Service&quot;,&quot;metadata&quot;:{&quot;annotations&quot;:{},&quot;name&quot;:&quot;partner-service&quot;,&quot;namespace&quot;:&quot;default&quot;},&quot;spec&quot;:{&quot;ports&quot;:[{&quot;port&quot;:1521,&quot;protocol&quot;:&quot;TCP&quot;,&quot;targetPort&quot;:1521}]}}
  creationTimestamp: &quot;2021-03-08T14:32:02Z&quot;
  labels:
    app: partner-db
  name: partner-service
  namespace: default
  resourceVersion: &quot;12574&quot;
  uid: b5106bef-a292-4a16-aafc-9676a81cd763
spec:
  clusterIP: 10.96.122.33
  clusterIPs:
  - 10.96.122.33
  ports:
  - port: 1521
    protocol: TCP
    targetPort: 1521
  selector:
    app: partner-db
  sessionAffinity: None
  type: ClusterIP
status:
  loadBalancer: {}
</code></pre>
<p>This throws error that ClusterIp is required. Is it possible to have 2 types of connections in the same service?</p>
<p>I also tried <code>k expose deployment partner-as --type=NodePort --ports=8080</code> but with the error service already exists</p>
<p>This runs on a vagrant VM where minikube is installed</p>
<p>As per the comment added a second service.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  creationTimestamp: &quot;2021-03-09T09:28:00Z&quot;
  labels:
    app: partner-as
  name: service-as
  namespace: default
  resourceVersion: &quot;16889&quot;
  uid: bed7ab44-c350-45e6-87c4-8aac037740c3
spec:
  clusterIP: 10.104.102.177
  clusterIPs:
  - 10.104.102.177
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 30029
    port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: partner-as
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}

</code></pre>
<p>and my ingress.yaml</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-as
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - host: partner.info
      http:
        paths:
          - path: /partner
            pathType: Prefix
            backend:
              service:
                name: service-as
                port:
                  number: 8080
</code></pre>
<p>Added partner.info in my etc hosts in the vagrant vm.</p>
<p>Still the IP is not accessible from ym local machine.(so no access from brwoser)</p>
<p>Describe my service-as</p>
<pre><code>Name:                     service-as
Namespace:                default
Labels:                   app=partner-as
Annotations:              &lt;none&gt;
Selector:                 app=partner-as
Type:                     NodePort
IP Families:              &lt;none&gt;
IP:                       10.104.102.177
IPs:                      10.104.102.177
Port:                     &lt;unset&gt;  8080/TCP
TargetPort:               8080/TCP
NodePort:                 &lt;unset&gt;  30029/TCP
Endpoints:                172.17.0.5:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>

Vini
<p>You can create <strong>two services</strong> with a different name but just keep the same <strong>selector</strong></p>
<p>To a single service, you can not apply <strong>multiple</strong> types. <code>ClusterIP</code> or <code>NodePort</code> you can only use <strong>one</strong></p>
<p>in a single file what you can do is like</p>
<p><strong>service.yaml</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: partner-db
  name: partner-service
  namespace: default
spec:
  ports:
  - port: 1521
    protocol: TCP
    targetPort: 1521
  selector:
    app: partner-db
  sessionAffinity: None
  type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: partner-db
  name: partner-service-node-port
  namespace: default
spec:
  ports:
  - port: 1521
    protocol: TCP
    targetPort: 1521
  selector:
    app: partner-db
  type: NodePort
</code></pre>
<p>For internal use you can use cluster IP but if you are looking forward to use or expose the service using <strong>Domain</strong> i would suggest you to use ingress.</p>
<p>For this</p>
<blockquote>
<p>app1--&gt;connects to app2(db via ClusterIP: port 1521) app1--&gt;expose to
ingress to access it from my browser</p>
</blockquote>
<p>If you are using the ingress you can use both service type as <code>ClusterIP</code> as you want to access your <strong>app1</strong> over browser.</p>
