当前位置:网站首页>Kubernetes resource object introduction and common commands (III)
Kubernetes resource object introduction and common commands (III)
2022-07-01 23:38:00 【Jiang Xiaonan】
Service
A set of Pods An abstract method that is exposed as a network service . It can also be understood as Pod Service discovery and load balancing .
Service discovery and load balancing :Service Will detect pod The state of , Traffic will only be sent to normal with average scores pod in .

establish Service
expose Deploy. port 8000.
Command line mode
[[email protected] ~]# kubectl expose deployment my-app --port=8000 --target-port=80
service/my-app exposed
[[email protected] ~]# kubectl get service
yaml The way ,service.yml
apiVersion: v1
kind: Service
metadata:
labels:
app: my-app
name: my-app
spec:
selector:
app: my-app
ports:
- port: 8000
protocol: TCP
targetPort: 80
[[email protected] ~]# kubectl apply -f service.yml
service/my-app created
[[email protected] ~]#
see Service
[[email protected] ~]# kubectl get service -n default
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 23h
my-app ClusterIP 10.96.2.98 <none> 8000/TCP 6s
[[email protected] ~]#
You can see what we created above Service Of ip by 10.96.2.98.
[[email protected] ~]# curl 10.96.2.98:8000
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
...
</html>
[[email protected] ~]#
Be careful : We can use ip:8000 In the form of any node access in the cluster . We can also do that pod Inside Use domain name : port Form access . The form of domain name :service name . Namespace .svc: port . for example :my-app.default.svc:8000.
Expand :
see pod label
[[email protected] ~]# kubectl get pod [podname] --show-labels
NAME READY STATUS RESTARTS AGE LABELS
my-app-5ff664f457-l7792 1/1 Running 1 20h app=my-app,pod-template-hash=5ff664f457
my-app-5ff664f457-r69z5 1/1 Running 1 20h app=my-app,pod-template-hash=5ff664f457
my-app-5ff664f457-w2d6q 1/1 Running 1 20h app=my-app,pod-template-hash=5ff664f457
my-app-5ff664f457-xsz9l 1/1 Running 1 20h app=my-app,pod-template-hash=5ff664f457
[[email protected] ~]#
Use tags to retrieve Pod
[[email protected] ~]# kubectl get pod -l app=my-app
NAME READY STATUS RESTARTS AGE
my-app-5ff664f457-l7792 1/1 Running 1 20h
my-app-5ff664f457-r69z5 1/1 Running 1 20h
my-app-5ff664f457-w2d6q 1/1 Running 1 20h
my-app-5ff664f457-xsz9l 1/1 Running 1 20h
[[email protected] ~]#
Delete Service
[[email protected] ~]# kubectl delete service my-app
service "my-app" deleted
[[email protected] ~]#
ClusterIP

We created Service The default is ClusterIP, It's called clustering ip, It can only be used inside the cluster . Equate to :
kubectl expose deployment my-app --port=8000 --target-port=80 --type=ClusterIP
apiVersion: v1
kind: Service
metadata:
labels:
app: my-app
name: my-app
spec:
ports:
- port: 8000
protocol: TCP
targetPort: 80
selector:
app: my-app
type: ClusterIP
NodePort

Created this way Service It can also be accessed outside the cluster . Because he will be in every pod Show a new port .
Command line mode
[[email protected] ~]# kubectl expose deploy my-app --port=8000 --target-port=80 --type=NodePort
service/my-app exposed
[[email protected] ~]#
yaml The way .service.yml
apiVersion: v1
kind: Service
metadata:
labels:
app: my-app
name: my-app
spec:
ports:
- port: 8000
protocol: TCP
targetPort: 80
selector:
app: my-app
type: NodePort
kubectl apply -f service.yml
[[email protected] ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 25h
my-app NodePort 10.96.198.191 <none> 8000:32047/TCP 39s
[[email protected] ~]#
Contrast found in PORT(S) A mapping port is added in 32047, This port is available on every node , Can pass node ip:30247 Access outside the cluster .

NodePort In addition to being accessible outside the cluster , The rest and ClusterIP Agreement .
Summary
NodePort The scope is 30000-32767 Randomly generated between . ClusterIP Can only be used within a cluster . NodePort Can pass node ip: new portAccess outside the cluster .Whether it's ClusterIP still NodePort, Will generate CLUSTER-IP, It can be used in the cluster .Use ip: portTo use on cluster nodes , anddomain name : portTo be in pod Internal use .How to write a domain name : service name . In the namespace .svc
边栏推荐
- Redis master-slave synchronization
- 力扣今日题-241. 为运算表达式设计优先级
- 为什么PHP叫超文本预处理器
- from pip._ internal. cli. main import main ModuleNotFoundError: No module named ‘pip‘
- 【ES实战】ES上的安全性运行方式
- MT manager test skiing Adventure
- Notblank and notempty
- vs2015 AdminDeployment.xml
- Why is PHP called hypertext preprocessor
- 每日三题 6.29
猜你喜欢

Redis RDB快照

Redis data types and application scenarios

2022 crane driver (limited to bridge crane) examination questions and simulation examination

Using uni simple router, dynamically pass parameters typeerror: cannot convert undefined or null to object
![[understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing](/img/08/9ecfd53a04e147022dde3449aec132.png)
[understanding of opportunity-35]: Guiguzi - flying clamp - the art of remote connection, remote control and remote testing

硅谷产品实战学习感触

Redis RDB snapshot

Matplotlib common settings

【必会】BM41 输出二叉树的右视图【中等+】

SWT / anr problem - SWT causes kernel fuse deadlock
随机推荐
SWT/ANR问题--SWT 导致 low memory killer(LMK)
神经网络物联网的发展趋势和未来方向
Deep learning | three concepts: epoch, batch, iteration
物联网开发零基础教程
Redis 主从同步
dat. GUI
Switch to software testing, knowing these four points is enough!
2022 safety officer-c certificate examination question simulation examination question bank and simulation examination
Yunxin small class | common cognitive misunderstandings in IM and audio and video
SWT / anr problem - SWT causes low memory killer (LMK)
jpa手写sql,用自定义实体类接收
为什么PHP叫超文本预处理器
2021 RoboCom 世界机器人开发者大赛-高职组初赛
ShanDong Multi-University Training #3
Overview of edge calculation
Matplotlib common charts
notBlank 和 notEmpty
Daily three questions 6.30 (2)
Notblank and notempty
TS初次使用、ts类型