KodeKloud Challenges: Kubernetes Challenge 4
Check KodeKloud’s Kubernetes Challenge #4!
Note - if you really must see the solutions directly, find them on my GitHub page; okbobm!
What’s the scenario? Build a highly available Redis Cluster based on the given architecture diagram.
What are the general requirements for this challenge?
- Create service (i.e. redis-cluster-service)
- Create persistent volumes x6 (i.e. redis01-resdis06)
- Create sts (i.e redis-cluster)
- Run script
Step 1: Create service (i.e. redis-cluster-service)
Requirements:
- Ports - service name ‘redis-cluster-service’, port name: ‘client’, port: ‘6379’
- Ports - service name ‘redis-cluster-service’, port name: ‘gossip’, port: ‘16379’
- Ports - service name ‘redis-cluster-service’, port name: ‘client’, targetPort: ‘6379’
- Ports - service name ‘redis-cluster-service’, port name: ‘gossip’, targetPort: ‘16379’
Solution:
- Create a yaml file for the redis-cluster-service
- Apply from yaml
- k apply -f vote-deployment.yaml
- Check service was created successfully
- k get svc
- Apply from yaml
Step 2: Create persistent volumes x6 (i.e. redis01-resdis06)
Note - this step grouped for all 6 persistent volumes
Requirements:
- PersistentVolume - Name: redis01
- Access modes: ReadWriteOnce
- Size: 1Gi
- hostPath: /redis01, directory should be created on worker node
Solution:
- Create a yaml file for the pv-redis0x
- Option 1 - create all pv’s from one file, quickly modifying values for each pv set in the file. This is the option I used for this challenge to quickly get through the challenge, also with the exam mentality of a “quick and dirty” solution.
- Apply from yaml
- k apply -f pv-redis0x.yaml
- Check persistent volumes was created successfully
- k get pv
- Apply from yaml
- Option 2 - the better option (and goal of devsecops) is to script and automate whenever possible see here for a good option to script the creation of the 6 pv files.
- Option 1 - create all pv’s from one file, quickly modifying values for each pv set in the file. This is the option I used for this challenge to quickly get through the challenge, also with the exam mentality of a “quick and dirty” solution.
Step 3: Create sts (i.e.redis-cluster-service)
Requirements:
- StatefulSet - Name: redis-cluster
- Replicas: 6
- Pods status: Running (All 6 replicas)
- Image: redis:5.0.1-alpine, Label = app: redis-cluster
- container name: redis, command: [“/conf/update-node.sh”, “redis-server”, “/conf/redis.conf”]
- Env: name: ‘POD_IP’, valueFrom: ‘fieldRef’, fieldPath: ‘status.podIP’ (apiVersion: v1)
- Ports - name: ‘client’, containerPort: ‘6379’
- Ports - name: ‘gossip’, containerPort: ‘16379’
- Volume Mount - name: ‘conf’, mountPath: ‘/conf’, readOnly:’false’ (ConfigMap Mount)
- Volume Mount - name: ‘data’, mountPath: ‘/data’, readOnly:’false’ (volumeClaim)
- volumes - name: ‘conf’, Type: ‘ConfigMap’, ConfigMap Name: ‘redis-cluster-configmap’,
- Volumes - name: ‘conf’, ConfigMap Name: ‘redis-cluster-configmap’, defaultMode = ‘0755’
- volumeClaimTemplates - name: ‘data’
- volumeClaimTemplates - accessModes: ‘ReadWriteOnce’
- volumeClaimTemplates - Storage Request: ‘1Gi’
Solution:
- Create a yaml file for the redis-cluster-service
- Apply from yaml
- k apply -f redis-cluster-service.yaml
- Check sts was created successfully
- k get svs
- Apply from yaml
Step 4: Run script
Requirements:
- Run command
Solution:
- kubectl exec -it redis-cluster-0 – redis-cli –cluster create –cluster-replicas 1 $(kubectl get pods -l app=redis-cluster -o jsonpath=’{range.items[*]}{.status.podIP}:6379 {end}’)
- Click yes for full setup