- Learn OpenShift
- Denis Zuev Artemii Kropachev Aleksey Usov
- 286字
- 2021-08-13 16:03:52
Exposing Kubernetes services
When we run a pod using the kubectl run command, this pod is accessible only inside Kubernetes. In most of cases, we would want this pod to be accessible from the outside as well. This is where the kubectl expose command comes in handy. Let's create the httpd pod one more time and then expose it to the outside world:
$ kubectl run httpd --image=httpd
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
httpd-66c6df655-8h5f4 1/1 Running 0 27m
Now let's use the kubectl expose command and expose the httpd web server to the outside of Kubernetes:
$ kubectl expose pod httpd-66c6df655-8h5f4 --port=80 --name=httpd-exposed --type=NodePort
While using the kubectl expose command, we specify several options:
- port: Pod (Docker container) port that we are going to expose to the outside of the Kubernetes cluster.
- name: Kubernetes service name.
- type: Kubernetes service type. NodePort uses Kubernetes Node IP.
The command to get a list of exposed Kubernetes services is kubectl get services:
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 1d
httpd-exposed NodePort 10.110.40.149<none> 80:31395/TCP 3s
Also, there is a ClusterIP field with the IP address 10.110.40.149 allocated for the httpd-expose service. Do not pay attention to this at the moment; we are going to discuss this later in the book.
Finally, use curl to check if the httpd server is available from the outside of the Kubernetes cluster:
$ curl 192.168.99.101:31395
<html><body><h1>It works!</h1></body></html>
If you open this link in your web browser, you should see It works! on the web page.
- 操作系統(tǒng)基礎(chǔ)與實踐:基于openEuler平臺
- 玩到極致 iPhone 4S完全攻略
- Java EE 8 Design Patterns and Best Practices
- 零基礎(chǔ)學(xué)鴻蒙PC:新一代國產(chǎn)操作系統(tǒng)
- Windows Server 2012網(wǎng)絡(luò)操作系統(tǒng)項目教程(第4版)
- 云原生落地:產(chǎn)品、架構(gòu)與商業(yè)模式
- 寫給架構(gòu)師的Linux實踐:設(shè)計并實現(xiàn)基于Linux的IT解決方案
- Red Hat Enterprise Linux 6.4網(wǎng)絡(luò)操作系統(tǒng)詳解
- Troubleshooting Docker
- 從實踐中學(xué)習(xí)Windows滲透測試
- 應(yīng)急指揮信息系統(tǒng)設(shè)計
- 電腦辦公(Windows 10 + Office 2016)入門與提高(超值版)
- Zabbix監(jiān)控系統(tǒng)之深度解析和實踐
- Android NDK Beginner's Guide
- Windows 8完全自學(xué)手冊