Kubernetes CKAD weekly challenge #2 Namespaces, Deployments and Services

Kim Wuestkamp
Apr 1, 2019 · 3 min read
Image for post
Image for post

ALL CHALLENGES AND TIPS

Rules!

  1. be fast, avoid creating yaml manually from scratch

Notices

Todays Task: Namespaces, Deployments and Services

  1. Create a new namespace k8s-challenge-2-a and assure all following operations (unless different namespace is mentioned) are done in this namespace.

Solution

use kubectl >= 1.18alias k=kubectl

1. Namespace

k create ns k8n-challenge-2-ak config current-context # show current context
docker-for-desktop
# now set default namespace for context
k config set-context docker-for-desktop --namespace=k8n-challenge-2-a
# or simply use the --current flag, thanks to Anton!
k config set-context --current --namespace=k8n-challenge-2-a

2. Deployment

k create deploy nginx-deployment --image=nginx -o yaml --dry-run=client > nginx-deployment.yaml

Deprecated:

# DEPRECATED and won't work with 1.18
k run nginx-deployment --image=nginx --replicas 3 --limits=memory=64Mi -o yaml --dry-run > nginx-deployment.yaml

Now edit nginx-deployment.yaml to define our memory restrictions and our containerPort:

k create -f nginx-deployment.yaml

Our watch command should output something like this:

Image for post
Image for post

3. Expose / Service

k expose deployment nginx-deployment --name=nginx-service --port=4444 --target-port=80
Image for post
Image for post

4. Pod1

k run -it pod1 --image=cosmintitei/bash-curl --restart=Never --rm
Image for post
Image for post

5. Pod2

k create ns k8n-challenge-2-bk run -it pod2 --image=cosmintitei/bash-curl --restart=Never --namespace=k8n-challenge-2-b --rm
Image for post
Image for post

So here we can reach our nginx-service using curl http://nginx-service.k8n-challenge-2-a:4444 .

End

We learned how to use namespaces and how pods from different namespaces can reach each other via DNS. We also looked at spinning up pods with/without deployment to fit different use cases.

Amazed by k8s already like I am? Well, it’s getting better :)

ALL CHALLENGES AND TIPS

More on

Image for post
Image for post
https://killer.sh

FAUN

The Must-Read Publication for Creative Developers & DevOps Enthusiasts

Sign up for FAUN

By FAUN

Medium’s largest and most followed independent DevOps publication. Join thousands of aspiring developers and DevOps enthusiasts Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Kim Wuestkamp

Written by

wuestkamp.com | killer.sh (CKS CKA CKAD Simulator) | Software Engineer, Infrastructure Architect, Certified Kubernetes, Certified Symfony

FAUN

FAUN

The Must-Read Publication for Creative Developers & DevOps Enthusiasts. Medium’s largest DevOps publication.

Kim Wuestkamp

Written by

wuestkamp.com | killer.sh (CKS CKA CKAD Simulator) | Software Engineer, Infrastructure Architect, Certified Kubernetes, Certified Symfony

FAUN

FAUN

The Must-Read Publication for Creative Developers & DevOps Enthusiasts. Medium’s largest DevOps publication.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store