Deploy a K8s Service
A service is an abstraction to access Replication Controllers containers outside of the cluster. Service Types: a) ClusterIp (internal IP) b) NodePort (public IP) c) LoadBalancer (NodePort to cloud based LB) Some background: - Client will connect to RCs or Pods? No - Client will connect to a Service (IP,DNS,Port are stable) - Remind that RCs and Pods are Ephemeral and Unstable. - Remind also that Pods run in Nodes (minions) - Pods are connected to Services via LABELS - A Service is basically a label selector - A Service contains a Load Balancer - A Service has built-in Service Discovery by DNS based Outcomes of creating a service: - Endpoint Docs: https://kubernetes.io/docs/concepts/services-networking/service/
Create a Service from an RC
kubectl expose rc sampleapp-rc --name=sampleapp-svc --target-port=80 --type=NodePort
Cross check the newly created service
kubectl describe svc sampleapp-svc
NodePort: <unset> 31903/TCP
kubectl cluster-info
https://192.168.64.2:8443/
Port range will always be: 30000 / 32767
Get the Cluster Public IP Address
kubectl cluster-info
minikube service sampleapp-svc --url
List all Services
kubectl get svc
Delete a Service
kubectl delete svc sampleapp-svc
Declare a Service
kind: Service
apiVersion: v1
metadata:
name: sampleapp-svc
labels:
app: sampleapp
spec:
type: NodePort
ports:
- port: 80
nodePort: 30001
protocol: TCP
selector:
app: sampleapp
Load yml into apiServer
kubectl create -f svc-blueprint.yml
Cross check
kubectl get svc
kubectl describe svc sampleapp-svc
Open in browser
kubectl cluster-info
chrome http://192.168.64.2:30001/
Created on 5/21/2018