Using Services
Challenge
Use kubectl
to
- Create a deployment
kubectl create deployment lab2 --image=sirfragalot/docker-demo:dcus
- Create a service to expose your deployment
- Access the service internally from the cluster
- Access the service externally from the cluster
- Describe services
Expand here to see the solution
Solution
doc reference
kubectl expose deployment lab2 --name=lab2-svc --port=80 --target-port=8080
kubectl run -it --image=busybox bash
/ # wget lab2-svc
kubectl expose deployment lab2 --name=lab2-np --type=NodePort --port=8080
kubectl get svc lab2-np
curl ifconfig.me
curl http://34.82.35.166:30595 (or use your web browser)
kubectl describe svc
Challenge
Use kubectl
to
- Create a pod
kubectl run redis --image=redis
- Create a service called redis-svc to expose the redis pod within the cluster on port 6379
- Describe service
Expand here to see the solution
Solution
doc reference
kubectl expose deployment redis --name=redis-svc --port=6379
kubectl run -it --image=busybox bash
/ # wget redis-service
kubectl describe svc
Challenge
Use kubectl
to
- Create a pod called
my-nginx
and expose it on container port 8080
.
Expand here to see the solution
Solution
kubectl run my-nginx --image=nginx --port=8080
kubectl describe pod my-nginx
Challenge
Use kubectl
to
- Create a pod called
httpd
using the image httpd:alpine
in the default
namespace.
- Next, create a service of type ClusterIP by the same name (httpd).
- The target port for the service should be 80.
Expand here to see the solution
Solution
kubectl run httpd --image=httpd:alpine --namespace default
kubectl expose pod httpd --port=80
kubectl describe pod my-nginx