<p>If I run command</p>

<pre><code>kubectl expose deployments/some-app --type=NodePort
</code></pre>

<p>it works.</p>

<p>If I run command </p>

<pre><code>kubectl apply -f expose.yml
</code></pre>

<p>Where the content of expose.yml is</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: some-app
  labels:
    app: some-app
spec:
  type: NodePort
  ports:
    - port: 8080
  selector:
    app: some-app
</code></pre>

<p>I cannot reach the service.</p>

<p>What is the difference? Why the 2nd approach does not work?</p>

<p>EDIT: Use NodePort in the yml as well</p>

<p>EDIT:
Result of command <code>kubectl expose deployments/some-app --type=NodePort --dry-run -o yaml</code>:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: some-app
    type: spring-app
  name: some-app
spec:
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    name: some-app
  type: NodePort
status:
  loadBalancer: {}
</code></pre>

Saphyra
<p>In your expose command you use <code>--type=NodePort</code>, but in svc <code>type=ClusterIP</code>. If you want to see what expose command created then add <code>--dry-run --o yaml</code> at the end of the command. You should see like following.</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    run: some-app
  name: some-app
spec:
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: some-app
  type: NodePort
</code></pre>

<p>NB: After discussion in comment, you need to ensure <code>app: some-app</code> exists on pod leve.</p>
