- To create a service run
$ kubectl create -f kubapp-svc.yaml- To list the services run:
$ kubectl get svc- To remotely execute command in running container run:
$ kubectl exec <name_of_the_pod> -- curl -s http://address- To configure session affinity on the service run:
$ kubectl create -f kubapp-svc-affinity.yaml
$ kubectl exec <name_of_the_pod> -- curl -s http://addressNote: you will hit the same pod
- Accessing the bash shell in a container inside a pod
$ kubectl exec -it <pods name> bashExample:
$ kubectl exec -it kubapp-ds72z bash
root@kubapp-ds72z:/# curl http://kubapp
You've hit kubapp-ds72z
root@kubapp-ds72z:/# curl http://kubapp.default
You've hit kubapp-ds72z
root@kubapp-ds72z:/# cat /etc/resolv.conf
search default.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.0.0.10
options ndots:5
- Create endpoints and service separately:
$ kubectl create -f kubapp-endpoints.yaml
$ kubectl create -f kubapp-manual-svc-endpoint.yamlCheck service' functionality via:
$ kubectl exec <name of the pod> -- curl http://ip_of_the_service-
An example of the ExternalName service can be found here
-
An example of exposing service externally by setting an external IP address on it can be found here
-
An example of a NodePort service can be found here
-
An example of a LoadBalancer service can be found here
If you wanna test it with Minikube, run
$ minikube service <name of the service>- For the Ingress testing, activate Ingress addon in minikube first:
$ minikube addons enable ingressthen create the Ingress service (example is here)
$ kubectl create -f ingress.yamlcheck that Ingress service was created successfully
$ kubectl get ing
NAME HOSTS ADDRESS PORTS AGE
kubapp-ingress kubapp.example.com 192.168.99.100 80 18hcheck Ingress functionality:
$ curl 192.168.99.100Edit RC settings:
$ kubectl edit rc kubappand add something like:
spec:
containers:
- name: kubapp
image: evalle/kubapp
readinessProbe:
exec:
command:
- ls
- /var/ready
then delete your previos pods and check pods again:
$ kubectl delete po --all
$ kubectl get po
NAME READY STATUS RESTARTS AGE
kubapp-7hfz8 0/1 Running 0 9m
kubapp-fvhv7 0/1 Running 0 9m
kubapp-lvlxr 0/1 Running 0 9m
To make one of the pods ready run
$ kubectl exec kubapp-7hfz8 -- touch /var/ready
Check pod's status again
$ kubectl get po
NAME READY STATUS RESTARTS AGE
kubapp-7hfz8 1/1 Running 0 12m
kubapp-fvhv7 0/1 Running 0 12m
kubapp-lvlxr 0/1 Running 0 12m
$ kubectl run dnsutils --image=tutum/dnsutils --generator=run-pod/v1 \
--command -- sleep infinity
pod "dnsutils" created