Kubectl expose: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 6: Line 6:


<tt>expose</tt> dynamically exposes a resource, which can be a pod, service, replicationcontroller, deployment or replicaset as a new service.  
<tt>expose</tt> dynamically exposes a resource, which can be a pod, service, replicationcontroller, deployment or replicaset as a new service.  
=Expose a Pod=


If a pod is used, the command  
If a pod is used, the command  
Line 17: Line 19:
</syntaxhighlight>
</syntaxhighlight>


 
=Expose a Higher Level Controller=


If a replication controller, deployment or replicset are used, the command
If a replication controller, deployment or replicset are used, the command

Revision as of 00:00, 20 September 2020

Internal

Overview

expose dynamically exposes a resource, which can be a pod, service, replicationcontroller, deployment or replicaset as a new service.

Expose a Pod

If a pod is used, the command

kubectl [-n <namespace>] expose pod <pod-name> --port=<port> --target-port=<target-port> --name=<service-name> [--type=ClusterIP|NodePort|...]
kubectl expose pod httpd --port=9898 --target-port=80 --name=httpd-svc

Expose a Higher Level Controller

If a replication controller, deployment or replicset are used, the command




The default service type is ClusterIP, other type (NodePort, LoadBalancer, or ExternalName) can be specified with --type.

kubectl [-n default] expose pod pg-0 --port=5432 --target-port=5432 --name=postgres --type=NodePort

TODO: I don't seem to see the service with kubectl get services, but attempting to connect to the database works.