Add a couple of Kubernetes questions and exercises
In addition, changed the order of some Linux questions.
This commit is contained in:
		
							
								
								
									
										62
									
								
								exercises/kubernetes/solutions/replicaset_01_solution.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								exercises/kubernetes/solutions/replicaset_01_solution.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,62 @@
 | 
			
		||||
## ReplicaSet 01 - Solution
 | 
			
		||||
 | 
			
		||||
1. Create a ReplicaSet with 2 replicas. The app can be anything.
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
cat >> rs.yaml <<EOL
 | 
			
		||||
apiVersion: apps/v1
 | 
			
		||||
kind: ReplicaSet
 | 
			
		||||
metadata:
 | 
			
		||||
  name: web
 | 
			
		||||
  labels:
 | 
			
		||||
    app: somewebapp
 | 
			
		||||
    type: web
 | 
			
		||||
spec:
 | 
			
		||||
  replicas: 2
 | 
			
		||||
  selector:
 | 
			
		||||
    matchLabels:
 | 
			
		||||
      type: web
 | 
			
		||||
  template:
 | 
			
		||||
    metadata:
 | 
			
		||||
      labels:
 | 
			
		||||
        type: web
 | 
			
		||||
    spec:
 | 
			
		||||
      containers:
 | 
			
		||||
      - name: httpd
 | 
			
		||||
        image: registry.redhat.io/rhscl/httpd-24-rhel7
 | 
			
		||||
EOL
 | 
			
		||||
 | 
			
		||||
kubectl apply -f rs.yaml
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
2. Verify a ReplicaSet was created and there are 2 replicas
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
kubectl get rs
 | 
			
		||||
# OR a more specific way: kubectl get -f rs.yaml
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
3. Delete one of the Pods the ReplicaSet has created
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
kubectl delete po <POD_NAME>
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
4. If you'll list all the Pods now, what will you see?
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
The same number of Pods. Since we defined 2 replicas, the ReplicaSet will make sure to create another Pod that will replace the one you've deleted.
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
5. Remove the ReplicaSet you've created
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
kubectl delete -f rs.yaml
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
6. Verify you've deleted the ReplicaSet
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
kubectl get rs
 | 
			
		||||
# OR a more specific way: kubectl get -f rs.yaml
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										62
									
								
								exercises/kubernetes/solutions/replicaset_02_solution.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								exercises/kubernetes/solutions/replicaset_02_solution.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,62 @@
 | 
			
		||||
## ReplicaSet 02 - Solution
 | 
			
		||||
 | 
			
		||||
1. Create a ReplicaSet with 2 replicas. The app can be anything.
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
cat >> rs.yaml <<EOL
 | 
			
		||||
apiVersion: apps/v1
 | 
			
		||||
kind: ReplicaSet
 | 
			
		||||
metadata:
 | 
			
		||||
  name: web
 | 
			
		||||
  labels:
 | 
			
		||||
    app: somewebapp
 | 
			
		||||
    type: web
 | 
			
		||||
spec:
 | 
			
		||||
  replicas: 2
 | 
			
		||||
  selector:
 | 
			
		||||
    matchLabels:
 | 
			
		||||
      type: web
 | 
			
		||||
  template:
 | 
			
		||||
    metadata:
 | 
			
		||||
      labels:
 | 
			
		||||
        type: web
 | 
			
		||||
    spec:
 | 
			
		||||
      containers:
 | 
			
		||||
      - name: httpd
 | 
			
		||||
        image: registry.redhat.io/rhscl/httpd-24-rhel7
 | 
			
		||||
EOL
 | 
			
		||||
 | 
			
		||||
kubectl apply -f rs.yaml
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
2. Verify a ReplicaSet was created and there are 2 replicas
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
kubectl get rs
 | 
			
		||||
# OR a more specific way: kubectl get -f rs.yaml
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
3. Remove the ReplicaSet but NOT the pods it created
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
kubectl delete -f rs.yaml --cascade=false
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
4. Verify you've deleted the ReplicaSet but the Pods are still running
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
kubectl get rs # no replicas
 | 
			
		||||
kubectl get po # Pods still running
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
5. Create again the same ReplicaSet, without changing anything
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
kubectl apply -f rs.yaml
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
6. Verify that the ReplicaSet used the existing Pods and didn't create new Pods
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
kubectl describe rs web  # You should see there are no new events and if you list the pods with 'kubectl get po -f rs.yaml` you'll see they have the same names
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										61
									
								
								exercises/kubernetes/solutions/replicaset_03_solution.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								exercises/kubernetes/solutions/replicaset_03_solution.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,61 @@
 | 
			
		||||
## ReplicaSet 03 - Solution
 | 
			
		||||
 | 
			
		||||
1. Create a ReplicaSet with 2 replicas. Make sure the label used for the selector and in the Pods is "type=web"
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
cat >> rs.yaml <<EOL
 | 
			
		||||
apiVersion: apps/v1
 | 
			
		||||
kind: ReplicaSet
 | 
			
		||||
metadata:
 | 
			
		||||
  name: web
 | 
			
		||||
  labels:
 | 
			
		||||
    app: somewebapp
 | 
			
		||||
    type: web
 | 
			
		||||
spec:
 | 
			
		||||
  replicas: 2
 | 
			
		||||
  selector:
 | 
			
		||||
    matchLabels:
 | 
			
		||||
      type: web
 | 
			
		||||
  template:
 | 
			
		||||
    metadata:
 | 
			
		||||
      labels:
 | 
			
		||||
        type: web
 | 
			
		||||
    spec:
 | 
			
		||||
      containers:
 | 
			
		||||
      - name: httpd
 | 
			
		||||
        image: registry.redhat.io/rhscl/httpd-24-rhel7
 | 
			
		||||
EOL
 | 
			
		||||
 | 
			
		||||
kubectl apply -f rs.yaml
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
2. Verify a ReplicaSet was created and there are 2 replicas
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
kubectl get rs
 | 
			
		||||
# OR a more specific way: kubectl get -f rs.yaml
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
3. List the Pods running and save the output somewhere
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
kubectl get po > running_pods.txt
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
4. Remove the label (type=web) from one of the Pods created by the ReplicaSet
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
kubectl label pod <POD_NAME> type-
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
5. List the Pods running. Are there more Pods running after removing the label? Why?
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
Yes, there is an additional Pod running because once the label, used as a matching selector, was removed, the Pod became independant meaning, it's not controlled by the ReplicaSet anymore and the ReplicaSet was missing replicas based on its definition so, it created a new Pod.
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
6. Verify the ReplicaSet indeed created a new Pod
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
kubectl describe rs web
 | 
			
		||||
```
 | 
			
		||||
		Reference in New Issue
	
	Block a user