0% found this document useful (0 votes)
7 views10 pages

Kubernetes Ckad 2

The document provides a comprehensive guide on Kubernetes commands related to pod design, services, volumes, Helm, and Custom Resource Definitions (CRD). It includes commands for creating, managing, and deleting pods, deployments, services, jobs, and cron jobs, as well as Helm chart operations and CRD management. Each section contains specific commands with examples to facilitate understanding and practical application.

Uploaded by

Kisham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views10 pages

Kubernetes Ckad 2

The document provides a comprehensive guide on Kubernetes commands related to pod design, services, volumes, Helm, and Custom Resource Definitions (CRD). It includes commands for creating, managing, and deleting pods, deployments, services, jobs, and cron jobs, as well as Helm chart operations and CRD management. Each section contains specific commands with examples to facilitate understanding and practical application.

Uploaded by

Kisham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

KUBERNETES CKAD 2

1. POD DESIGN
kubectl run nginx1 --image=nginx --restart=Never -l app=v1 Create a pod named nginx1 with the label
app=v1.
kubectl get po --show-labels Show all pods with their labels.
kubectl label po nginx2 app=v2 --overwrite Change the label of the pod nginx2 to app=v2.
kubectl get po -l app=v2 Get all pods with the label app=v2.
kubectl label po -l "app in (v1,v2)" tier=web Add the label tier=web to pods with labels app=v1 or app=v2.
kubectl annotate po nginx2 owner=marketing Add the annotation owner=marketing to the pod nginx2.
kubectl label po -l app app- Remove the app label from all pods with the app label.
kubectl annotate po nginx1 description='my description' Add an annotation description='my description' to
the pod nginx1.
kubectl annotate po nginx1 --list List all annotations on the pod nginx1.
kubectl annotate po nginx{1..3} description- owner- Remove the annotations description and owner from
pods nginx1, nginx2, and nginx3.
kubectl delete po nginx{1..3} Delete pods nginx1, nginx2, and nginx3.
kubectl label nodes <node-name> accelerator=nvidia-tesla-p100 Add the label accelerator=nvidia-tesla-
p100 to a node.
kubectl get nodes --show-labels Show all nodes with their labels.
kubectl taint node node1 tier=frontend:NoSchedule Add a taint tier=frontend:NoSchedule to the node
node1.
kubectl taint node node1 tier=frontend:NoSchedule- Remove the taint tier=frontend:NoSchedule from the
node node1.
kubectl create deployment nginx --image=nginx:1.18.0 --replicas=2 --port=80 Create a deployment
named nginx with 2 replicas, using image nginx:1.18.0, exposing port 80.
kubectl get deploy nginx -o yaml View the YAML definition of the nginx deployment.
kubectl set image deploy nginx nginx=nginx:1.19.8 Update the deployment nginx to use the image
nginx:1.19.8.
kubectl rollout status deploy nginx Check the rollout status of the deployment nginx.
kubectl rollout undo deploy nginx Undo the latest rollout for the deployment nginx.
kubectl scale deploy nginx --replicas=5 Scale the deployment nginx to 5 replicas.
kubectl autoscale deploy nginx --min=5 --max=10 --cpu-percent=80 Autoscale the deployment nginx
between 5 and 10 replicas, targeting 80% CPU usage.
kubectl rollout pause deploy nginx Pause the rollout of the deployment nginx.
kubectl rollout resume deploy nginx Resume the rollout of the deployment nginx.
kubectl create job pi --image=perl:5.34 -- perl -Mbignum=bpi -wle 'print bpi(2000)' Create a job named pi
to calculate the value of π.
kubectl get jobs View all jobs in the cluster.
kubectl logs job/pi View the logs of the job pi.
kubectl delete job pi Delete the job pi.
kubectl create cronjob busybox --image=busybox --schedule="*/1 * * * *" -- /bin/sh -c 'date; echo Hello
from the Kubernetes cluster' Create a cron job named busybox that runs every minute and prints a
message.
kubectl get cj List all cron jobs in the cluster.
kubectl delete cj busybox Delete the cron job busybox.
kubectl create job --from=cronjob/busybox sample-job Create a job named sample-job from the cron job
busybox.

2. Services
kubectl run nginx --image=nginx --restart=Never --port=80 --expose Create a pod named nginx
with image nginx and expose it as a ClusterIP service on port 80.
kubectl get svc nginx Display details about the service created for the nginx pod.
kubectl get ep Check the endpoints associated with all services in the cluster.
IP=$(kubectl get svc nginx --template={{.spec.clusterIP}}) Get the ClusterIP of the nginx service
and store it in a variable.
kubectl run busybox --rm --image=busybox -it --restart=Never --env="IP=$IP" -- wget -O- $IP:80 --
timeout 2 Create a temporary busybox pod and use wget to hit the nginx service on its ClusterIP.
kubectl patch svc nginx -p '{"spec":{"type":"NodePort"}}' Change the type of the nginx service
from ClusterIP to NodePort.
wget -O- <NODE_IP>:<NODE_PORT> Access the nginx service using the Node’s IP and
NodePort.
kubectl delete svc nginx Delete the nginx service.
kubectl delete pod nginx Delete the nginx pod.
kubectl create deploy foo --image=dgkanatsios/simpleapp --port=8080 --replicas=3 Create a
deployment named foo with 3 replicas, using the image dgkanatsios/simpleapp, and expose port
8080 on its containers.
kubectl get pods -l app=foo -o wide List all pods with the label app=foo and include their IP
addresses.
kubectl run busybox --image=busybox --restart=Never -it --rm -- sh Create a temporary interactive
busybox pod to run commands.
wget -O- <POD_IP>:8080 Use wget within the busybox pod to connect to one of the foo
deployment pods on port 8080.
kubectl expose deploy foo --port=6262 --target-port=8080 Expose the foo deployment as a
ClusterIP service on port 6262, mapping to the target port 8080 of the containers.
kubectl get svc foo Display details of the foo service.
kubectl get endpoints foo Check the endpoints for the foo service to verify they match the pod
IPs.
kubectl run busybox --image=busybox -it --rm --restart=Never -- sh Create a temporary busybox
pod to test the foo service.
wget -O- foo:6262 Test the foo service using DNS within the busybox pod.
wget -O- <SERVICE_CLUSTER_IP>:6262 Test the foo service using its ClusterIP.
kubectl delete svc foo Delete the foo service.
kubectl delete deploy foo Delete the foo deployment.
kubectl create deployment nginx --image=nginx --replicas=2 Create an nginx deployment with 2
replicas.
kubectl expose deployment nginx --port=80 Expose the nginx deployment as a ClusterIP service
on port 80.
kubectl create -f policy.yaml Apply a NetworkPolicy from the policy.yaml file to restrict access to
the nginx pods.
kubectl run busybox --image=busybox --rm -it --restart=Never -- wget -O- http://nginx:80 --timeout
2 Create a temporary busybox pod to test access to the nginx service without the required labels.
kubectl run busybox --image=busybox --rm -it --restart=Never --labels=access=granted -- wget -
O- http://nginx:80 --timeout 2 Create a temporary busybox pod with the label access=granted and
test access to the nginx service.

3. Volumes
4. HELM
helm create chart-test Create a basic Helm chart named chart-test.
helm install -f myvalues.yaml myredis ./redis Install a Helm chart located in the
redis directory with values from myvalues.yaml. Name the release myredis.
helm list --pending -A List all pending Helm deployments across all namespaces.
helm uninstall -n namespace release_name Uninstall a Helm release in the
specified namespace.
helm upgrade -f myvalues.yaml -f override.yaml redis ./redis Upgrade the redis
release using the Helm chart in the redis directory with values from
myvalues.yaml and override.yaml.
helm repo add [NAME] [URL] Add a Helm chart repository with the given name
and URL.
helm repo list List all added Helm repositories.
helm repo remove [REPO1] Remove a specified Helm repository.
helm repo update Update all Helm repositories to fetch the latest charts.
helm repo index [DIR] Generate an index file for the charts in the specified
directory.
helm pull [chart URL | repo/chartname] Download a Helm chart from the specified
repository or URL.
helm pull --untar [repo/chartname] Download and extract a Helm chart from the
specified repository.
helm repo add bitnami https://charts.bitnami.com/bitnami Add the Bitnami Helm
chart repository to your list of Helm repositories.
helm show values bitnami/node Display the contents of the values.yaml file for
the bitnami/node chart.
helm install mynode bitnami/node --set replicaCount=5 Install the bitnami/node
chart with a release name mynode and set the number of replicas to 5 using the -
-set flag.
5. CRD

kubectl apply -f operator-crd.yml


This command applies the operator-crd.yml manifest to create a
CustomResourceDefinition (CRD) named operators.stable.example.com in
the Kubernetes API. The CRD defines a new custom resource called Operator with a
schema (email, name, and age), scope (Namespaced), and names (plural:
operators, singular: operator, shortNames: op).

kubectl apply -f operator.yml


This command applies the operator.yml manifest to create a custom resource of type
Operator. The custom resource has the name operator-sample and a spec with
the fields email, name, and age. This custom object conforms to the CRD schema
defined in the previous step.

kubectl get operators


This command lists all custom resources of type Operator using the plural name
operators. It provides an overview of all resources defined under the CRD.

kubectl get operator


This command lists all custom resources of type Operator using the singular name
operator. It is an alternative way to fetch the same resources listed with the plural
form.

kubectl get op
This command lists all custom resources of type Operator using the short name op. It
is a convenient shorthand defined in the CRD for quickly accessing the resources.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy