Saturday, July 11, 2020

kubernetes-imperative command practice

Q:
Deploy a pod named nginx-pod using the nginx:alpine image.
Use imperative commands only.
Name: nginx-pod
Image: nginx:alpinex

 kubectl run nginx-pod --image=nginx:alpine --dry-run=client -o yaml > nginx- pod.yaml
 (This will create the nginx-pod.yaml and now we can vi to it to verify all specs are correct)

vi nginx-pod.yaml

( And finally, create the pod using the yaml file)
kubectl apply -f nginx-pod.yaml


Q. Deploy a redis pod using the redis:alpine image with the labels set to tier=db. Either use imperative commands to create the pod with the labels. Or else use imperative commands to generate the pod definition file, then add the labels before creating the pod using the file. info_outline Hint Pod Name: redis
 Image: redis:alpine Labels: tier=db


 kubectl run redis --image=redis:alpine -l tier=db --dry-run=client -o yaml > redis.yaml
 kubectl get pod
 vi redis.yaml
 kubectl apply-f redis.yaml


Create a service redis-service to expose the redis application within the cluster on port 6379. Use imperative commands info_outline Hint 
Service: redis-service Port: 6379 Type: ClusterIp Selector: tier=db

kubectl expose pod  redis --type=ClusterIP  --name=redis-service --port=6379 --dry-run=client -o yaml > redis-service.yaml.  ( using expose command will select the selector from pod automatically)
vi redis-service.yaml
kubectl apply -f redis-service.yaml




Create a deployment named webapp using the image kodekloud/webapp-color with 3 replicas Try to use imperative commands only. Do not create definition files. info_outline Hint 
Name: webapp Image: kodekloud/webapp-color Replicas: 3


master $ kubectl create deployment webapp  --image=kodekloud/webapp-color
deployment.apps/webapp created
master $ kubectl scale deployment webapp --replicas=3
deployment.apps/webapp scaled
master $ ls -ltr



Create a new pod called custom-nginx using the nginx image and expose it on container port 8080

master $ kubectl run custom-nginx --image=nginx --port=8080 --dry-run=client -o yaml > custom-nginx.yaml
master $ vi custom-nginx.yaml
master $ kubectl apply -f custom-nginx.yaml
pod/custom-nginx created


Create a new deployment called redis-deploy in the dev-ns namespace with the redis image. It should have 2 replicas. Use imperative commands. info_outline Hint redis-deploy created in the dev-ns namespace? replicas: 2


 kubectl create deployment redis-deploy --image=redis --namespace dev-ns --dry-run=client -o yaml > redis-deploy.yaml
vi redis-deploy.yaml
kubectl scale deployment  redis-deploy --replicas=3
kubectl apply -f redis-deploy.yaml
kubectl scale deployment  redis-deploy --replicas=3
kubectl get deployment
kubectl get deployment webapp --replicas=3
kubectl scale deployment webapp --replica=3
vi redis-deploy.yaml
kubectl scale deployment webapp --replica=3  --namespace ns-dev
kubectl scale deployment redis-deploy --replicas=3  --namespace ns-dev
kubectl get ns
kubectl scale deployment redis-deploy --replicas=3 --namespace dev-ns
history


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. Try to do this with as few steps as possible. info_outline Hint `httpd` pod created with the correct image? 'httpd' service is of type 'clusterIP'? 'httpd' service uses correct target port 80? 'httpd' service exposes the 'httpd' pod?


master $ kubectl run httpd --image=httpd:alpine
pod/httpd created
master $ kubectl expose httpd --type=ClusterIP --name=httpd --port=80
error: the server doesn't have a resource type "httpd"
See 'kubectl expose -h' for help and examples
master $ kubectl expose httpd --type=ClusterIP --name=ht^Cd --port=80
master $ kubectl get pods
NAME                      READY   STATUS    RESTARTS   AGE
custom-nginx              1/1     Running   0          12m
httpd                     1/1     Running   0          84s
redis                     1/1     Running   0          35m
webapp-7cd5749f95-7f7sv   1/1     Running   0          18m
webapp-7cd5749f95-9zxc7   1/1     Running   0          19m
webapp-7cd5749f95-hngz9   1/1     Running   0          18m
master $ kubectl expose pod httpd --type=ClusterIP --name=httpd --port=80
service/httpd exposed






No comments:

Post a Comment