Check KodeKloud’s Kubernetes Challenge #1!. I’ll start out with I love these kinds of real world challenges, to get you thinking about solving things outside of your day-to-day operations. I’m looking forward to posting KodeKloud (and other platform) solutions. I’ve certainly benefited from others providing (gentle) guidance to solving challenges, and I’m hoping to do the same on this blog.

Please note - In some cases I’m providing the actual solution on GitHub, but try to figure these challenges out on your own first! If you really must see the solutions directly, find them on my GitHub page; okbobm. Good luck!

What’s the scenario? Deploy the given architecture diagram for implmenting a Jekyll SSG below:

Challenge1

What are the general requirements for this challenge?

  1. KubeConfig file modification (user information and context)
  2. Create a role (i.e. “developer-role”)
  3. Create role-binding (i.e. “developer-rolebinding”) to that role
  4. Create persistent volume claim (i.e. jekyll-pvc)
  5. Create pod (i.e. jekyll)
  6. Create service (i.e. jekyll-node-service)
  7. Set context (created in step 1)
  8. Note - persistent volume (i.e. jekyll-pv) already created

Step 1: KubeConfig file modification (user information and context)

Requirements:

  • Build user information for martin in the default kubeconfig file: User = martin , client-key = /root/martin.key and client-certificate = /root/martin.crt
  • Create a new context called ‘developer’ in the default kubeconfig file with ‘user = martin’ and ‘cluster = kubernetes’

Solution:

  • This one solution is fairly quick, within the kubeconfig file set the credentials and then set the context;
    • kconfig set-credentials martin –client-certificate ./martin.crt –client-key ./martin.key
    • k config set-context developer –cluster kubernetes –user martin

Step 2: Create a role (i.e. “developer-role”)

Requirements:

  • ‘developer-role’, should have all(*) permissions for services in development namespace
  • ‘developer-role’, should have all permissions(*) for persistentvolumeclaims in development namespace
  • ‘developer-role’, should have all(*) permissions for pods in development namespace

Solution:

  • Create a yaml file for the role
  • Apply from yaml
    • k apply -f role.yaml

Step 3: Create a role binding (i.e. “developer-rolebinding”)

Requirements:

  • create rolebinding = developer-rolebinding, role= ‘developer-role’, namespace = development
  • rolebinding = developer-rolebinding associated with user = ‘martin’

Solution:

  • Create a yaml file for the role binding
  • Apply from yaml
    • k apply -f rolebinding.yaml

Step 4: Create persistent volume claim (i.e. jekyll-pvc)

Requirements:

  • Storage Request: 1Gi
  • Access modes: ReadWriteMany
  • pvc name = jekyll-site, namespace = development
  • ‘jekyll-site’ PVC should be bound to the PersistentVolume called ‘jekyll-site’.

Solution:

Step 5: Create pod (i.e. jekyll)

Requirements:

  • pod: ‘jekyll’ has an initContainer, name: ‘copy-jekyll-site’, image: ‘kodekloud/jekyll’
  • initContainer: ‘copy-jekyll-site’, command: [ “jekyll”, “new”, “/site” ] (command to run: jekyll new /site)
  • pod: ‘jekyll’, initContainer: ‘copy-jekyll-site’, mountPath = ‘/site’
  • pod: ‘jekyll’, initContainer: ‘copy-jekyll-site’, volume name = ‘site’
  • pod: ‘jekyll’, container: ‘jekyll’, volume name = ‘site’
  • pod: ‘jekyll’, container: ‘jekyll’, mountPath = ‘/site’
  • pod: ‘jekyll’, container: ‘jekyll’, image = ‘kodekloud/jekyll-serve’
  • pod: ‘jekyll’, uses volume called ‘site’ with pvc = ‘jekyll-site’
  • pod: ‘jekyll’ uses label ‘run=jekyll’

Solution:

  • Create a yaml file for the pod
  • Apply from yaml
    • k apply -f pod.yaml

Step 6: Create service (i.e. jekyll-node-service)

Requirements:

  • Service ‘jekyll’ uses targetPort: ‘4000’, namespace: ‘development’
  • Service ‘jekyll’ uses Port: ‘8080’, namespace: ‘development’
  • Service ‘jekyll’ uses NodePort: ‘30097’, namespace: ‘development’

Solution:

  • Create a yaml file for the service
  • Apply from yaml
    • k apply -f service.yaml
  • Note there is a “gottcha” here if you aren’t paying attention to the individual arrows. Make sure you add (to the service file): selector: run: jekyll

Step 7: Set context in KubConfg (created in step 1)

Requirements:

  • set context ‘developer’ with user = ‘martin’ and cluster = ‘kubernetes’ as the current context.

Solution:

  • kubectl config use-context developer

Finally - completed!

You should see everything in green as in the diagram below:

Challenge1_completed

Future bonus points: write a script to complete all the scripts at once!

(Find something in error or that could be done better? Contact me! I would love to hear from you.)