Giriş
Expose a resource as a new Kubernetes service.
Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. [...]
1. deployment İçin
Tüm worker node'lar port açar. Pod'a erişmek için her hangi bir worker nodu'un IP adresini kullanılabilir.
Örnek - LoadBalancer
kubectl expose deployment your-deployment-name \
--type=LoadBalancer \
--port=80 \
--target-port=9092
Örnek - LoadBalancer
$ kubectl expose deployment
$( kubectl get deployment --selector="planetscale.com/component=vtgate"
-o=jsonpath="{.items..metadata.name}" )
--type=LoadBalancer
--name=test-vtgate
--port 3306
--target-port 3306
$ kubectl get service test-vtgate
------
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
test-vtgate LoadBalancer [cluster_ip] [external_ip] 3306:32157/TCP 90s
2. pod İçin
Sadece tek bir pod'a port açar. Pod'a erişmek için bu pod'un çalıştığı worker node'un IP adresini kullanmak gerekir.
Örnek
Şöyle
yaparız. nodePort numarası otomatik olarak veriliyor.
kubectl expose pod rabbitmq-0 --port=15672 --target-port=15672 --type=NodePort
Örnek - nodePort
Şöyle yaparız. Dahili
12340 portu dışarıya
30869 olarak açılır. nodePort numarası otomatik olarak veriliyor.
kubectl expose pod rlwy-proc-blue-6db5798f55-m2fmp --port=12340 --target-port=12340
--type=NodePort --name imgw1
servisin detayları şöyledir. Burada
IP: 172.30.135.252 yazıyor ama aslında bu IP adresi kullanılamaz.
Bu pod'un çalıştığı worker node'un IP adresini kullanmak gerekir.$ kubectl describe svc imgw1
Name: imgw1
Namespace: rlwy-04
Labels: app=oce-rlwy-proc
chartColor=blue
ne=rlwy
pod-template-hash=6db5798f55
processingGroup=true
release=rlwy-04-oce-rlwy-proc-blue
runsCommManager=true
Annotations: <none>
Selector: app=oce-rlwy-proc,...
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 172.30.135.252
IPs: 172.30.135.252
Port: <unset> 12340/TCP
TargetPort: 12340/TCP
NodePort: <unset> 30869/TCP
Endpoints: 10.130.4.19:12340
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
Örnek - LoadBalancer
Bunu denemedim ama tahminen şöyle yaparız. Böylece bir pod dış dünyaya açılır
kubectl expose pod rlwy-proc-blue-6db5798f55-m2fmp --port=12340 --target-port=12340
--type=LoadBalancer --name imgw1 -n rlwy-04
servise bakınca şöyledir
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S)
imgw1 LoadBalancer 172.30.8.31 104.198.194.171 12340:31762/TCP
servisin detayları şöyledir
$ kubectl describe svc imgw1
Name: imgw1
Namespace: rlwy-04
Labels: app=oce-rlwy-proc
chartColor=blue
ne=rlwy
pod-template-hash=6db5798f55
processingGroup=true
release=rlwy-04-oce-rlwy-proc-blue
runsCommManager=true
Annotations: <none>
Selector: app=oce-rlwy-proc,chartColor=blue,...
Type: LoadBalancer
IP Family Policy: SingleStack
IP Families: IPv4
IP: 172.30.8.31
IPs: 172.30.8.31
LoadBalancer Ingress: 104.198.194.171
Port: <unset> 12340/TCP
TargetPort: 12340/TCP
NodePort: <unset> 31762/TCP
Endpoints: 10.130.4.19:12340
Session Affinity: None
External Traffic Policy: Cluster
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal EnsuringLoadBalancer 8m4s service-controller Ensuring load balancer
Normal EnsuredLoadBalancer 7m31s service-controller Ensured load balancer
Örnek - LoadBalancer
kubectl expose pod odsa-spring --type LoadBalancer --port 80 --target-port 8080