CKAD

1.Core Concepts

Create a namespace called 'mynamespace' and a pod with image nginx called nginx on this namespace

$ kubectl create namespace mynamespace
$ kubectl get ns
NAME STATUS AGE
mynamespace Active 6m13s
$ kubectl run nginx --image=nginx --restart=Never -n mynamespace
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 5m2s

Create the pod that was just described using YAML

kubectl run nginx --image=nginx --restart=Never --dry-run=client -n mynamespace -o yaml > pod.yaml

cat pod.yaml

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx
spec:
  containers:
  - image: nginx
    name: nginx
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}

delete old nginx pod and recreate one

kubectl delete po nginx -n mynamespace
kubectl create -f pod.yaml -n mynamespace

Alternatively, you can run in one line

kubectl run nginx --image=nginx --restart=Never --dry-run=client -o yaml | kubectl create -n mynamespace -f -

 

Create a busybox pod (using kubectl command) that runs the command "env". Run it and see the output

$ kubectl run busybox --image=busybox --command --restart=Never -it -- env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=busybox
TERM=xterm
KUBERNETES_PORT=tcp://10.244.64.1:443
KUBERNETES_PORT_443_TCP=tcp://10.244.64.1:443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_ADDR=10.244.64.1
KUBERNETES_SERVICE_HOST=10.244.64.1
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_PORT_HTTPS=443
HOME=/root

$ kubectl run busybox --image=busybox --command --restart=Never -- env
pod/busybox created

$ kubectl logs busybox
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=busybox KUBERNETES_PORT_443_TCP_PROTO=tcp KUBERNETES_PORT_443_TCP_PORT=443 KUBERNETES_PORT_443_TCP_ADDR=10.244.64.1 KUBERNETES_SERVICE_HOST=10.244.64.1 KUBERNETES_SERVICE_PORT=443 KUBERNETES_SERVICE_PORT_HTTPS=443 KUBERNETES_PORT=tcp://10.244.64.1:443 KUBERNETES_PORT_443_TCP=tcp://10.244.64.1:443 HOME=/root

 

Create a busybox pod (using YAML) that runs the command "env". Run it and see the output

$ kubectl run busybox --image=busybox --restart=Never --dry-run=client -o yaml --command -- env > envpod.yaml

$ cat envpod.yam
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: busybox
  name: busybox
spec:
  containers:
  - command:
    - env
    image: busybox
    name: busybox
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}

$ kubectl apply -f envpod.yaml
pod/busybox created

# kubectl logs busybox
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=busybox KUBERNETES_SERVICE_PORT_HTTPS=443 KUBERNETES_PORT=tcp://10.244.64.1:443 KUBERNETES_PORT_443_TCP=tcp://10.244.64.1:443 KUBERNETES_PORT_443_TCP_PROTO=tcp KUBERNETES_PORT_443_TCP_PORT=443 KUBERNETES_PORT_443_TCP_ADDR=10.244.64.1 KUBERNETES_SERVICE_HOST=10.244.64.1 KUBERNETES_SERVICE_PORT=443 HOME=/root

 

Get the YAML for a new namespace called 'myns' without creating it

# kubectl create namespace myns -o yaml --dry-run=client
apiVersion: v1
kind: Namespace
metadata:
  creationTimestamp: null
  name: myns
spec: {}
status: {}

 

Get the YAML for a new ResourceQuota called 'myrq' with hard limits of 1 CPU, 1G memory and 2 pods without creating it

 

 

 

 

 

 

Create a busybox pod (using kubectl command) that runs the command "env". Run it and see the output

show

Create a busybox pod (using YAML) that runs the command "env". Run it and see the output

show

Get the YAML for a new namespace called 'myns' without creating it

show

Get the YAML for a new ResourceQuota called 'myrq' with hard limits of 1 CPU, 1G memory and 2 pods without creating it

show

Get pods on all namespaces

show

Create a pod with image nginx called nginx and expose traffic on port 80

show

Change pod's image to nginx:1.7.1. Observe that the container will be restarted as soon as the image gets pulled

show

Get nginx pod's ip created in previous step, use a temp busybox image to wget its '/'

show

Get pod's YAML

show

Get information about the pod, including details about potential issues (e.g. pod hasn't started)

show

Get pod logs

show

If pod crashed and restarted, get logs about the previous instance

show

Execute a simple shell on the nginx pod

show

Create a busybox pod that echoes 'hello world' and then exits

show

Do the same, but have the pod deleted automatically when it's completed

show

Create an nginx pod and set an env value as 'var1=val1'. Check the env value existence within the pod

show    
上一篇:curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused


下一篇:80、8080、443端口