Container Images and Practical


Let me share few useful container images to play around with K8s

1. katacoda/docker-http-server
2. k8s.gcr.io/echoserver:1.10
3. nginx
4. busybox
- command: 
  - tail
  - -f
  - /dev/null
5. mendhak/http-https-echo
6.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: echoserver
spec:
  replicas: 3
  selector:
    matchLabels:
      app: echoserver
  template:
    metadata:
      labels:
        app: echoserver
    spec:
      containers:
      - image: gcr.io/google_containers/echoserver:1.0
        imagePullPolicy: Always
        name: echoserver
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: echoserver
spec:
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP
  selector:
    app: echoserver
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: echoserver
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: echo.example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: echoserver
          servicePort: 80
---
7. curl
apiVersion: apps/v1 
kind: Deployment
metadata:
  name: client
  namespace: cli
spec:
  selector:
    matchLabels:
      app: cli
  replicas: 1
  template:
    metadata:
      labels:
        app: cli
    spec:
      containers:
      - name: client
        image: curlimages/curl:latest
        env:
        - name: ADDRESS
          value: "service_name.svc.cluster.local"
        command: [ "/bin/sh""-c""while true; do date; curl $ADDRESS 2>/dev/null | grep '<title>'; sleep 0.5; done;" ]

8. kubectl run -it --rm test --image=curlimages/curl --restart=Never -- /bin/sh

9. Docker Image: us-docker.pkg.dev/google-samples/containers/gke/hello-app:2.0

K8s microservice: kubectl expose deploy hw11 --port=80 --target-port=8080 --dry-run=client -o yaml

Script : please run in pod as per 8 above. 

while true; 
do curl n2iwf;
sleep 1; 
done

10. Echo server: hashicorp/http-echo:0.2.3 Port 5678

Here are example Dockerfiles

Here are few posts about hands on with K8s


CKA and CKAD: My Notes and Website Links


Let me post all links, for CKA and CKAD exam


CKA


To know more about K8s from my blog

Apart form there are many links material on Internet. Here is the list of website, that I am aware about

https://github.com/StenlyTU/K8s-training-official

https://www.shrlrn.com/

https://www.manning.com/books/kubernetes-in-action#toc

https://amartus.com/amartus-kubernetes-exam-tips/


CKAD
https://itnext.io/the-kubernetes-workloads-3bcf99168c05
https://itnext.io/introduction-to-stateful-services-kubernetes-6018fd99338d
https://itnext.io/learn-how-to-configure-your-kubernetes-apps-using-the-configmap-object-d8f30f99abeb

https://github.com/kelseyhightower/kubernetes-the-hard-way around 10 hrs
https://azure.microsoft.com/en-in/resources/kubernetes-up-and-running/
https://kubernetes.io/
https://discuss.kubernetes.io/
https://kubernetes.io/training/
https://training.linuxfoundation.org/training/kubernetes-for-developers/#outline
https://www.edx.org/course/introduction-to-kubernetes
https://www.edx.org/course/introduction-to-linux
https://killer.sh/course/preview/e84d0e31-4fff-4c42-8afd-be1bdbc0d994
https://github.com/dgkanatsios/CKAD-exercises/blob/master/a.core_concepts.md
https://kubernetes.io/docs/reference/kubectl/cheatsheet/
https://learnk8s.io/troubleshooting-deployments
https://learnk8s.io/academy
https://kodekloud.com/
https://kubernauts.de/en/training/kubernetes-training-course.html
https://docs.google.com/presentation/d/13EQKZSQDounPC1I6EC4PmqaRmdCrpT3qswQJz9KRCyE/edit#slide=id.g33599df588_13_58  It has many excerises
https://collabnix.github.io/kubelabs/
https://www.katacoda.com/courses/kubernetes/playground
https://www.youtube.com/watch?v=c63qr8EFVWE
https://docs.google.com/spreadsheets/d/10NltoF_6y3mBwUzQ4bcQLQfCE1BWSgUDcJXy-Qp2JEU/edit#gid=0
https://killer.sh/
https://github.com/ShubhamTatvamasi/kubernetes-practice-tests
https://github.com/suchakra012/kubernetes-practice-tests

CKA Tips


 * Network Policy: 

- If we put podSelector: {} then it means all pods

- if we do not mention about podSelector at all, then it means none of the pod. 

* We can set env, sa, image, selector, and resources (Requests and Limit)  with kubectl set command

* We can set subject (user | sa | group) for rolebinding | clusterrolebinding

* now (k8s 1.18) kubectl run is only for pod. Not for deployment and job

* We cannot create pv, pvc , .... cannot be with kubectl create

* With 'kubectl expose' command we cannot specify nodePort value. With kubectl create service we can. 

* with 'kubectl create deploy' we can specify replica. Not containerPort

kubectl auth can-i VERB_ACTION RESOURCE_OBJECT --as USER --namespace NS

kubectl explain K8s_OBJECT is useful. kubectl explain K8s_OBJECT --recursive is more useful

kubectl api-resources is useful to know short form

* grep -A N , grep -B N, grep -C N: Here N is number of line. A means after, B is before 

* to run on specific node : nodeName

* mount secret : secretName ; mount configMap : name at Volumes section

* securityContext.capabilities is only for container, not for pod

* useful command: kubectl config set-context --current --namespace=default

* verify taint with kubectl describe node | grep -i Taint

* If we edit replicaset, it impacts when new pod is created. 

* If replicaset is part of deployment and if we delete replicaset, it will be recreate with same name. 

* If pod is part of replicaset and if we delete pod, it will be created with different name. 

* Replicaset has name. Pod has genearateName