Kubernetes Service Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(10 intermediate revisions by the same user not shown)
Line 2: Line 2:
* [[Kubernetes Operations#Service_Operations|Kubernetes Operations]]
* [[Kubernetes Operations#Service_Operations|Kubernetes Operations]]
* [[Kubernetes_Service_Concepts#Service_Operations|Kubernetes Service Concepts]]
* [[Kubernetes_Service_Concepts#Service_Operations|Kubernetes Service Concepts]]
=List Services=
<syntaxhighlight lang='bash'>
kubectl [-n <namespace>] get svc
</syntaxhighlight>
=Describe a Service=
<syntaxhighlight lang='bash'>
kubectl [-o yaml] get svc <service-name>
</syntaxhighlight>
<syntaxhighlight lang='bash'>
kubectl describe svc <service-name>
</syntaxhighlight>


=Create a Service=
=Create a Service=


==With CLI==
==With CLI==
A service of any type ([[Kubernetes_Service_Concepts#Service|ClusterIP]], [[Kubernetes_Service_Concepts#NodePort|NodePort]], [[Kubernetes_Service_Concepts#LoadBalancer|LoadBalancer]], or [[Kubernetes_Service_Concepts#ExternalName|ExternalName]]) can be created with the [[Kubectl_expose|kubectl expose]] command.
More details: {{Internal|kubectl expose|kubectl expose}}
==With Metadata==
Describe the service in a metadata YAML file:
<syntaxhighlight lang='yaml'>
apiVersion: v1
kind: Service
metadata:
  name: some-service
spec:
  selector:
    function: serves-http
  ports:
  - port: 80
    targetPort: 8888
</syntaxhighlight>
More details about the service manifest available in: {{Internal|Kubernetes Service Manifest|Kubernetes Service Manifest}}
POST it with:
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
kubectl apply -f ./service.yaml
</syntaxhighlight>


</syntaxhighlight>
=Service Troubleshooting=


==With Metadata==
Services can be tested as follows:
* Deploy an auxiliary pod, [[Kubectl_exec|kubectl exec]] into it and attempt to connect to the target pods via the service.
* ssh into a [[Kubernetes_Control_Plane_and_Data_Plane_Concepts#Node|Kubernetes node]] and use the [[curl]] command from there.
Check:
* Make sure to connect to a ClusterIP service from within the cluster not from outside.
* Pinging ClusterIP services does not work, the service's cluster IP is a virtual IP address.
* The readiness probe works correctly and returns the correct state.
* kubectl get endpoints
* Make sure you're using the service "port", not "targetPort"
* Try connecting to the pod directly, circumventing the service.
* If connecting to the pod directly does not work, make sure the application isn't only binding to localhost.

Latest revision as of 01:25, 21 September 2020

Internal

List Services

kubectl [-n <namespace>] get svc

Describe a Service

kubectl [-o yaml] get svc <service-name>
kubectl describe svc <service-name>

Create a Service

With CLI

A service of any type (ClusterIP, NodePort, LoadBalancer, or ExternalName) can be created with the kubectl expose command.

More details:

kubectl expose

With Metadata

Describe the service in a metadata YAML file:

apiVersion: v1
kind: Service
metadata:
  name: some-service
spec:
  selector:
    function: serves-http
  ports:
  - port: 80
    targetPort: 8888

More details about the service manifest available in:

Kubernetes Service Manifest

POST it with:

kubectl apply -f ./service.yaml

Service Troubleshooting

Services can be tested as follows:

  • Deploy an auxiliary pod, kubectl exec into it and attempt to connect to the target pods via the service.
  • ssh into a Kubernetes node and use the curl command from there.

Check:

  • Make sure to connect to a ClusterIP service from within the cluster not from outside.
  • Pinging ClusterIP services does not work, the service's cluster IP is a virtual IP address.
  • The readiness probe works correctly and returns the correct state.
  • kubectl get endpoints
  • Make sure you're using the service "port", not "targetPort"
  • Try connecting to the pod directly, circumventing the service.
  • If connecting to the pod directly does not work, make sure the application isn't only binding to localhost.