Kubectl expose: Difference between revisions
Jump to navigation
Jump to search
Line 33: | Line 33: | ||
=Expose a Service= | =Expose a Service= | ||
<font color= | <font color=darkkhaki>TODO | ||
kubectl expose deployment http-server --port=9999 --type=NodePort --name=http-service --overrides '{ "apiVersion": "v1","spec":{"ports": [{"port":9999,"protocol":"TCP","targetPort":9999,"nodePort":30999}]}}' | |||
</font> |
Revision as of 18:41, 6 December 2023
Internal
Overview
expose
dynamically exposes a resource, which can be a pod, another service, a deployment, replica set or a replication controller as a new service. If no service type is explicitly specified, ClusterIP is assumed. Specific service types (NodePort, LoadBalancer, or ExternalName) can be requested with --type
.
Expose a Pod
If a pod is used, the command reads the pod's labels and creates a service with a matching selector. By default, if no type is specified, ClusterIP is assumed.
kubectl [-n <namespace>] expose pod <pod-name> \
--name=<service-name> --port=<port> --target-port=<target-port> \
[--type=ClusterIP|NodePort|...]
kubectl expose pod httpd --name=httpd-svc --port=9898 --target-port=80
Expose a Higher Level Controller
If a replication controller, deployment or replicaset are used, the command reads their selector and re-uses it for the service being created.
Deployment
kubectl expose deployment my-deployment --name=my-service --type=ClusterIP
Expose a Service
TODO
kubectl expose deployment http-server --port=9999 --type=NodePort --name=http-service --overrides '{ "apiVersion": "v1","spec":{"ports": [{"port":9999,"protocol":"TCP","targetPort":9999,"nodePort":30999}]}}'