Orchestrating the Cloud with Kubernetes¶
gcloud container clusters create io
Create a cluster and get authenticated automatically for the duration of your Cloud Shell session. Use
gcloud container clusters get-credentials io to reauthenticate.
kubectl create deployment nginx --image=nginx:1.10.0 kubectl expose deployment nginx --port 80 --type LoadBalancer
So what just happened? Behind the scenes Kubernetes created an external Load Balancer with a public IP address attached to it. Any client who hits that public IP address will be routed to the pods behind the service. In this case that would be the nginx pod.
The utility of:
kubectl get services
In our case, we have:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.72.0.1 <none> 443/TCP 3m55s nginx LoadBalancer 10.72.4.91 220.127.116.11 80:30959/TCP 37s
- One or more containers
- One IP per pod
- Containers within a pod share a namespace
- Pods have Volumes By default, pods are not accessible outside of the cluster.
Hopping in to a container:
kubectl exec monolith --stdin --tty -c monolith -- /bin/sh
Pods are meant to be ephemeral: they'll be destroyed and recreated. So...what if you want to communicate with it? Enter: Services!
Using labels to manage Services:
kubectl label pods secure-monolith 'secure=enabled' kubectl get pods secure-monolith --show-labels
How do we manage and scale containers in production? Deployments!
Behind the scenes Deployments use Replica Sets to manage starting and stopping the Pods.