k8s service

由于博客内容为空,无法获取关键信息生成摘要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

kubectl create service clusterip wfq-svc-cp --tcp=80:8080

kubectl create service nodeport wfq-svc-np --tcp=1234:80

kubectl create service clusterip wfq-svc-headless --clusterip="None"


root@server02:~# kubectl create service clusterip wfq-svc-cp --tcp=80:8080
service "wfq-svc-cp" created
root@server02:~#
root@server02:~#
root@server02:~# kubectl create service nodeport wfq-svc-np --tcp=1234:80
service "wfq-svc-np" created
root@server02:~#
root@server02:~#
root@server02:~# kubectl create service clusterip wfq-svc-headless --clusterip="None"
service "wfq-svc-headless" created
root@server02:~#
root@server02:~#
root@server02:~# kubectl get svc
NAME                  TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
kubernetes            ClusterIP   10.68.0.1       <none>        443/TCP          226d
kubernetes-bootcamp   NodePort    10.68.70.33     <none>        80:34824/TCP     226d
my-nginx              ClusterIP   10.68.4.181     <none>        8090/TCP         22h
my-srv-cp             ClusterIP   10.68.45.143    <none>        80/TCP           23h
my-svc-headless       ClusterIP   None            <none>        <none>           23h
my-svc-np             NodePort    10.68.210.209   <none>        1234:24209/TCP   23h
nginx-service         NodePort    10.68.121.152   <none>        8080:20000/TCP   226d
wfq-svc-cp            ClusterIP   10.68.56.155    <none>        80/TCP           1m
wfq-svc-headless      ClusterIP   None            <none>        <none>           11s
wfq-svc-np            NodePort    10.68.108.6     <none>        1234:21388/TCP   40s
root@server02:~#
root@server02:~#
root@server02:~# kubectl describe service wfq-svc-cp
Name:              wfq-svc-cp
Namespace:         default
Labels:            app=wfq-svc-cp
Annotations:       <none>
Selector:          app=wfq-svc-cp
Type:              ClusterIP
IP:                10.68.56.155
Port:              80-8080  80/TCP
TargetPort:        8080/TCP
Endpoints:         <none>
Session Affinity:  None
Events:            <none>
root@server02:~#
root@server02:~# kubectl describe service wfq-svc-np
Name:                     wfq-svc-np
Namespace:                default
Labels:                   app=wfq-svc-np
Annotations:              <none>
Selector:                 app=wfq-svc-np
Type:                     NodePort
IP:                       10.68.108.6
Port:                     1234-80  1234/TCP
TargetPort:               80/TCP
NodePort:                 1234-80  21388/TCP
Endpoints:                <none>
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>
root@server02:~#
root@server02:~# kubectl describe service wfq-svc-headless
Name:              wfq-svc-headless
Namespace:         default
Labels:            app=wfq-svc-headless
Annotations:       <none>
Selector:          app=wfq-svc-headless
Type:              ClusterIP
IP:                None
Session Affinity:  None
Events:            <none>

### Kubernetes Service Configuration and Troubleshooting #### Understanding Services in Kubernetes In Kubernetes, services facilitate communication between different components within the cluster. A service groups a set of pods under a common access policy, allowing other applications to connect using this abstraction rather than directly connecting to individual pods[^1]. When no DNS solution is present, such as kube-dns, pods can still reach services by referencing environment variables injected into containers at creation time by the API server. This mechanism ensures that even without an internal DNS system, basic inter-service connectivity remains functional provided the service exists before any dependent pod starts up[^2]. #### Configuring Services Properly To ensure proper functioning of services: - Define clear selectors matching labels on target pods. - Specify appropriate ports both inside (`targetPort`) and outside (`port`). - Choose suitable types like ClusterIP (default), NodePort, LoadBalancer based on requirements. For example, configuring a simple HTTP-based web application might look something like below: ```yaml apiVersion: v1 kind: Service metadata: name: my- protocol: TCP port: 80 targetPort: 9376 ``` This YAML snippet creates a `ClusterIP` type service named `my-web-app-svc`, which routes traffic arriving at port 80 to all pods labeled with `app=my-web-app` listening internally on port 9376. #### Common Issues During Setup or Operation Several issues may arise during setup or operation including but not limited to network policies blocking connections, incorrect label selections causing mismatches between services and endpoints, misconfigured firewall rules preventing external access when using certain service types etc. One effective method for diagnosing problems involves checking logs from relevant resources via commands similar to these: ```bash kubectl get svc,pods,ep # Lists current state of services, pods, endpoint mappings kubectl describe svc <service-name> # Provides detailed information about specific service configurations kubectl logs <pod-name> [-c container] # Retrieves log output from specified pod/container ``` Additionally, tools mentioned earlier such as Prometheus for monitoring metrics could prove invaluable while tracking down performance bottlenecks or unexpected behavior patterns over time. --related questions-- 1. How does one configure Network Policies effectively alongside Services? 2. What are some best practices regarding security contexts applied to Pods serving through exposed Services? 3. Can you provide examples demonstrating how to implement advanced features offered by Ingress Controllers instead of relying solely upon standard Service definitions? 4. Are there recommended approaches towards automating scaling operations tied closely around observed load levels reported back from monitored instances behind Services?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值