├── session06 Kubernetes Ingress ├── ingress-note.txt └── ingress-sample │ ├── apple.ingress.yaml │ ├── banana.ingress.yaml │ ├── apple.yaml │ ├── banana.yaml │ └── app.ingress.yaml ├── session02-Installation ├── installation-server │ ├── install-kubectl.sh │ ├── hosts-template.ini │ └── configure-kubespray.sh ├── checkin_session02.png ├── installation steps.png ├── k8s-course-session02-Installation.pptx └── scripts │ ├── configure-vm.sh │ └── update-vm.sh ├── session11 scheduling ├── scheduling.emmx ├── k8s-course-session11 - Scheduling.pptx ├── pod-db-node1.yaml ├── pod-no-toleration.yaml ├── pod-node-selector.yaml ├── pod-with-toleration.yaml ├── deployment-node-selector.yaml ├── deployment-all-node.yml ├── deployment-pod-antiaffinity.yml ├── deployment-pod-affinity.yml ├── deployment-node-affinity.yml └── session 11 Practice.yml ├── session01-overview ├── k8s components2.png ├── k8s-course-session01-overview.pptx └── ~$k8s-course-session01-overview.pptx ├── session10 configmaps and secrets ├── secret.png ├── Overview.png ├── configmap1.png ├── configmap2.png ├── pod-configmap-env.png ├── pod-configmap-file.png ├── Configmap and Secret.emmx ├── pod-configmap-file.yml ├── pod-configmap-dir.yaml ├── practice-configmap-secret.txt └── pod-configmap-env.yml ├── session09 kubernetes storage ├── session09 kubernetes storage.pptx └── samples │ ├── pvc-nfs-delete.yml │ ├── pvc-nfs-retain.yml │ ├── viettq-pvc.yaml │ ├── viettq-pv.yaml │ └── viettq-pod.yaml ├── session05 Kubernetes Services ├── k8s-course-session05 - Kubernetes Services.pptx ├── service-lb.yaml ├── demo-pod.yaml ├── service-clusterip.yaml └── service-nodeport.yaml ├── session04 Deployment and replicaset ├── k8s-course-session04 - Kubernetes Deployment and ReplicaSet.pptx └── note.txt ├── PracticeTest 01 ├── Service-Example │ ├── service-clusterip.yaml │ └── service-nodeport.yaml ├── ReplicaSet-Example │ ├── replicaset-sample2.yaml │ ├── replicaset-sample1.yaml │ └── replicaset-sample3.yaml ├── Pod-Example │ ├── pod-multi-container.yaml │ └── pod-sample1.yaml └── Deployment-Example │ ├── deployment-sample1.yaml │ └── deployment-sample2.yaml ├── commit.sh └── session03-node and pods ├── pod-curl.yml ├── pod-multi-container.yml └── session3-tasks.txt /session06 Kubernetes Ingress/ingress-note.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /session02-Installation/installation-server/install-kubectl.sh: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /session11 scheduling/scheduling.emmx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session11 scheduling/scheduling.emmx -------------------------------------------------------------------------------- /session01-overview/k8s components2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session01-overview/k8s components2.png -------------------------------------------------------------------------------- /session02-Installation/checkin_session02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session02-Installation/checkin_session02.png -------------------------------------------------------------------------------- /session10 configmaps and secrets/secret.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session10 configmaps and secrets/secret.png -------------------------------------------------------------------------------- /session02-Installation/installation steps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session02-Installation/installation steps.png -------------------------------------------------------------------------------- /session10 configmaps and secrets/Overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session10 configmaps and secrets/Overview.png -------------------------------------------------------------------------------- /session10 configmaps and secrets/configmap1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session10 configmaps and secrets/configmap1.png -------------------------------------------------------------------------------- /session10 configmaps and secrets/configmap2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session10 configmaps and secrets/configmap2.png -------------------------------------------------------------------------------- /session01-overview/k8s-course-session01-overview.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session01-overview/k8s-course-session01-overview.pptx -------------------------------------------------------------------------------- /session10 configmaps and secrets/pod-configmap-env.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session10 configmaps and secrets/pod-configmap-env.png -------------------------------------------------------------------------------- /session10 configmaps and secrets/pod-configmap-file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session10 configmaps and secrets/pod-configmap-file.png -------------------------------------------------------------------------------- /session10 configmaps and secrets/Configmap and Secret.emmx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session10 configmaps and secrets/Configmap and Secret.emmx -------------------------------------------------------------------------------- /session11 scheduling/k8s-course-session11 - Scheduling.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session11 scheduling/k8s-course-session11 - Scheduling.pptx -------------------------------------------------------------------------------- /session02-Installation/k8s-course-session02-Installation.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session02-Installation/k8s-course-session02-Installation.pptx -------------------------------------------------------------------------------- /session09 kubernetes storage/session09 kubernetes storage.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session09 kubernetes storage/session09 kubernetes storage.pptx -------------------------------------------------------------------------------- /session01-overview/~$k8s-course-session01-overview.pptx: -------------------------------------------------------------------------------- 1 | 2 | Viet Trinh 3 | Viet Trinh -------------------------------------------------------------------------------- /session05 Kubernetes Services/k8s-course-session05 - Kubernetes Services.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session05 Kubernetes Services/k8s-course-session05 - Kubernetes Services.pptx -------------------------------------------------------------------------------- /session04 Deployment and replicaset/k8s-course-session04 - Kubernetes Deployment and ReplicaSet.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rockman88v/kubernetes_basic_course/HEAD/session04 Deployment and replicaset/k8s-course-session04 - Kubernetes Deployment and ReplicaSet.pptx -------------------------------------------------------------------------------- /session05 Kubernetes Services/service-lb.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: service-lb 5 | spec: 6 | type: LoadBalancer 7 | ports: 8 | - port: 80 9 | targetPort: 80 10 | nodePort: 30999 11 | selector: 12 | app: my-app 13 | apptype: frontend 14 | -------------------------------------------------------------------------------- /session09 kubernetes storage/samples/pvc-nfs-delete.yml: -------------------------------------------------------------------------------- 1 | kind: PersistentVolumeClaim 2 | apiVersion: v1 3 | metadata: 4 | name: pvc-delete 5 | spec: 6 | storageClassName: viettq-nfs-delete 7 | accessModes: 8 | - ReadWriteOnce 9 | resources: 10 | requests: 11 | storage: 10Mi 12 | -------------------------------------------------------------------------------- /session09 kubernetes storage/samples/pvc-nfs-retain.yml: -------------------------------------------------------------------------------- 1 | kind: PersistentVolumeClaim 2 | apiVersion: v1 3 | metadata: 4 | name: pvc-retain 5 | spec: 6 | storageClassName: viettq-nfs-retain 7 | accessModes: 8 | - ReadWriteOnce 9 | resources: 10 | requests: 11 | storage: 10Mi 12 | -------------------------------------------------------------------------------- /session09 kubernetes storage/samples/viettq-pvc.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: PersistentVolumeClaim 3 | metadata: 4 | name: viettq-pvc 5 | namespace: default 6 | spec: 7 | storageClassName: "" 8 | accessModes: 9 | - ReadWriteMany 10 | resources: 11 | requests: 12 | storage: 10Mi -------------------------------------------------------------------------------- /session05 Kubernetes Services/demo-pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: my-app 5 | labels: 6 | app: my-app 7 | apptype: frontend 8 | spec: 9 | containers: 10 | - name: nginx-container 11 | ports: 12 | - containerPort: 80 13 | name: http 14 | -------------------------------------------------------------------------------- /PracticeTest 01/Service-Example/service-clusterip.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: nginx-service 5 | spec: 6 | type: ClusterIP 7 | selector: 8 | name: nginx-deployment 9 | ports: 10 | - targetPort: 80 11 | port: 80 -------------------------------------------------------------------------------- /PracticeTest 01/Service-Example/service-nodeport.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: service-nodeport 5 | spec: 6 | type: nodePort 7 | selector: 8 | app: nginx-deployment 9 | ports: 10 | - targetPort: 8080 11 | port: 80 12 | nodePort: 30888 -------------------------------------------------------------------------------- /session11 scheduling/pod-db-node1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | creationTimestamp: null 5 | labels: 6 | app: db 7 | name: db-pod 8 | spec: 9 | containers: 10 | - image: nginx 11 | name: db-pod 12 | resources: {} 13 | nodeName: viettq-worker1 14 | dnsPolicy: ClusterFirst 15 | restartPolicy: Always 16 | status: {} 17 | 18 | -------------------------------------------------------------------------------- /PracticeTest 01/ReplicaSet-Example/replicaset-sample2.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: ReplicaSet 3 | metadata: 4 | name: replicaset-sample2 5 | spec: 6 | replicas: 2 7 | selector: 8 | matchLabels: 9 | tier: frontend 10 | template: 11 | metadata: 12 | labels: 13 | tier: nginx 14 | spec: 15 | containers: 16 | - name: nginx 17 | image: nginx -------------------------------------------------------------------------------- /commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | git status 5 | git add . 6 | msg="update document" 7 | msg=$1 8 | git config --global user.email "rockman88v@gmail.com" 9 | git config --global user.name "rockman88v" 10 | git remote set-url origin https://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@github.com/rockman88v/kubernetes_basic_course.git 11 | git commit -m "$msg" 12 | git push -u origin master 13 | 14 | -------------------------------------------------------------------------------- /session11 scheduling/pod-no-toleration.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | creationTimestamp: null 5 | labels: 6 | run: pod-no-toleration 7 | name: pod-no-toleration 8 | spec: 9 | containers: 10 | - image: nginx 11 | name: pod-no-toleration 12 | resources: {} 13 | nodeName: viettq-worker1 14 | dnsPolicy: ClusterFirst 15 | restartPolicy: Always 16 | status: {} -------------------------------------------------------------------------------- /session03-node and pods/pod-curl.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | creationTimestamp: null 5 | labels: 6 | run: pod-curl 7 | name: pod-curl 8 | spec: 9 | containers: 10 | - args: 11 | - /bin/sh 12 | - -c 13 | - sleep 3600 14 | image: busybox 15 | name: pod-curl 16 | resources: {} 17 | dnsPolicy: ClusterFirst 18 | restartPolicy: Always 19 | status: {} -------------------------------------------------------------------------------- /session11 scheduling/pod-node-selector.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | creationTimestamp: null 5 | labels: 6 | run: nginx 7 | name: my-nginx 8 | spec: 9 | containers: 10 | - image: nginx 11 | imagePullPolicy: IfNotPresent 12 | name: nginx 13 | resources: {} 14 | nodeSelector: 15 | disktype: ssd 16 | dnsPolicy: ClusterFirst 17 | restartPolicy: Always 18 | status: {} 19 | -------------------------------------------------------------------------------- /PracticeTest 01/Pod-Example/pod-multi-container.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: pods-multi-container-pod 5 | spec: 6 | containers: 7 | - image: busybox 8 | command: 9 | - sleep 10 | - "3600" 11 | name: pods-multi-container-container-1 12 | - image: busybox 13 | command: 14 | - sleep 15 | - "3601" 16 | name: pods-multi-container-container-2 -------------------------------------------------------------------------------- /session09 kubernetes storage/samples/viettq-pv.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: PersistentVolume 3 | metadata: 4 | name: viettq-pv 5 | spec: 6 | accessModes: 7 | - ReadWriteMany 8 | capacity: 9 | storage: 10Mi 10 | nfs: 11 | path: /data2/delete/viettq-pv #Path in NFS Data path 12 | server: 192.168.30.10 #IP of NFS server 13 | persistentVolumeReclaimPolicy: Retain 14 | claimRef: 15 | namespace: default 16 | name: viettq-pvc -------------------------------------------------------------------------------- /session06 Kubernetes Ingress/ingress-sample/apple.ingress.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1 2 | kind: Ingress 3 | metadata: 4 | annotations: 5 | name: apple.prod.viettq.com 6 | spec: 7 | ingressClassName: nginx 8 | rules: 9 | - host: apple.prod.viettq.com 10 | http: 11 | paths: 12 | - backend: 13 | service: 14 | name: apple-service 15 | port: 16 | number: 5678 17 | path: / 18 | pathType: Prefix -------------------------------------------------------------------------------- /session06 Kubernetes Ingress/ingress-sample/banana.ingress.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1 2 | kind: Ingress 3 | metadata: 4 | annotations: 5 | name: banana.prod.viettq.com 6 | spec: 7 | ingressClassName: nginx 8 | rules: 9 | - host: banana.prod.viettq.com 10 | http: 11 | paths: 12 | - backend: 13 | service: 14 | name: banana-service 15 | port: 16 | number: 5678 17 | path: / 18 | pathType: Prefix 19 | -------------------------------------------------------------------------------- /session06 Kubernetes Ingress/ingress-sample/apple.yaml: -------------------------------------------------------------------------------- 1 | kind: Pod 2 | apiVersion: v1 3 | metadata: 4 | name: apple-app 5 | labels: 6 | app: apple 7 | spec: 8 | containers: 9 | - name: apple-app 10 | image: hashicorp/http-echo 11 | args: 12 | - "-text=THIS_IS_APPLE" 13 | 14 | --- 15 | 16 | kind: Service 17 | apiVersion: v1 18 | metadata: 19 | name: apple-service 20 | spec: 21 | selector: 22 | app: apple 23 | ports: 24 | - port: 5678 # Default port for image -------------------------------------------------------------------------------- /session09 kubernetes storage/samples/viettq-pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: viettq-pod 5 | spec: 6 | volumes: 7 | - name: viettq-volume 8 | persistentVolumeClaim: 9 | claimName: viettq-pvc 10 | containers: 11 | - name: viettq-container 12 | image: nginx 13 | ports: 14 | - containerPort: 80 15 | name: "http-server" 16 | volumeMounts: 17 | - mountPath: "/usr/share/nginx/html" 18 | name: viettq-volume -------------------------------------------------------------------------------- /session06 Kubernetes Ingress/ingress-sample/banana.yaml: -------------------------------------------------------------------------------- 1 | kind: Pod 2 | apiVersion: v1 3 | metadata: 4 | name: banana-app 5 | labels: 6 | app: banana 7 | spec: 8 | containers: 9 | - name: banana-app 10 | image: hashicorp/http-echo 11 | args: 12 | - "-text=THIS_IS_BANANA" 13 | 14 | --- 15 | 16 | kind: Service 17 | apiVersion: v1 18 | metadata: 19 | name: banana-service 20 | spec: 21 | selector: 22 | app: banana 23 | ports: 24 | - port: 5678 # Default port for image -------------------------------------------------------------------------------- /session11 scheduling/pod-with-toleration.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | creationTimestamp: null 5 | labels: 6 | run: pod-toleration 7 | name: pod-toleration 8 | spec: 9 | containers: 10 | - image: nginx 11 | name: pod-toleration 12 | resources: {} 13 | nodeName: viettq-worker1 14 | tolerations: 15 | - key: "app" 16 | operator: Equal 17 | value: "special" 18 | effect: NoSchedule 19 | dnsPolicy: ClusterFirst 20 | restartPolicy: Always 21 | status: {} -------------------------------------------------------------------------------- /session03-node and pods/pod-multi-container.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | creationTimestamp: null 5 | labels: 6 | app: nginx 7 | apptype: webapp 8 | name: nginx-multi 9 | spec: 10 | containers: 11 | - image: nginx 12 | name: nginx1 13 | ports: 14 | - containerPort: 80 15 | - image: curlimages/curl 16 | name: curl 17 | args: 18 | - sh 19 | - -c 20 | - sleep 3600 21 | resources: {} 22 | dnsPolicy: ClusterFirst 23 | restartPolicy: Always 24 | status: {} -------------------------------------------------------------------------------- /session05 Kubernetes Services/service-clusterip.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: frontend-service 5 | spec: 6 | type: ClusterIP #Loại service: ClusterIP 7 | selector: #Khai báo rule để lọc các Pod mà service sẽ forward connection tới 8 | app: my-app 9 | apptype: frontend 10 | ports: 11 | - targetPort: 80 #Là port của Pod, service sẽ chuyển tiếp kết nối vào đây 12 | port: 80 #Là port được mở của Service. Client sẽ kết nối với Service qua port này 13 | -------------------------------------------------------------------------------- /PracticeTest 01/ReplicaSet-Example/replicaset-sample1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ReplicaSet 3 | metadata: 4 | name: replicaset-sample1 5 | spec: 6 | replicas: 2 7 | selector: 8 | matchLabels: 9 | app: frontend 10 | template: 11 | metadata: 12 | labels: 13 | app: frontend 14 | spec: 15 | containers: 16 | - name: nginx 17 | image: nginx 18 | resources: 19 | limits: 20 | cpu: 200m 21 | memory: 50Mi 22 | requests: 23 | cpu: 100m 24 | memory: 20Mi 25 | -------------------------------------------------------------------------------- /session02-Installation/installation-server/hosts-template.ini: -------------------------------------------------------------------------------- 1 | [all] 2 | viettq-master1 ansible_host=192.168.10.11 ip=192.168.10.11 3 | viettq-worker1 ansible_host=192.168.10.12 ip=192.168.10.12 4 | viettq-worker2 ansible_host=192.168.10.13 ip=192.168.10.13 5 | 6 | 7 | [kube-master] 8 | viettq-master1 9 | 10 | [kube-node] 11 | viettq-worker1 12 | viettq-worker2 13 | 14 | [etcd] 15 | viettq-master1 16 | 17 | [k8s-cluster:children] 18 | kube-node 19 | kube-master 20 | 21 | [calico-rr] 22 | 23 | [vault] 24 | viettq-master1 25 | viettq-worker1 26 | viettq-worker2 27 | -------------------------------------------------------------------------------- /session10 configmaps and secrets/pod-configmap-file.yml: -------------------------------------------------------------------------------- 1 | #Pod using config file from configmap 2 | apiVersion: v1 3 | kind: Pod 4 | metadata: 5 | name: print-configmap-file 6 | spec: 7 | containers: 8 | - name: env-print-demo 9 | image: busybox 10 | command: ["sh","-c","sleep 365d"] 11 | volumeMounts: 12 | - name: config-volume 13 | mountPath: "/app/config" 14 | readOnly: true 15 | volumes: 16 | - name: config-volume 17 | configMap: 18 | name: myapp-config 19 | items: 20 | - key: "introduction.txt" 21 | path: "introduction.txt" -------------------------------------------------------------------------------- /session02-Installation/scripts/configure-vm.sh: -------------------------------------------------------------------------------- 1 | #install some packages 2 | sudo yum update -y 3 | sudo yum install telnet -y 4 | sudo yum install bind-utils -y 5 | sudo yum install net-tools -y 6 | sudo yum install bash-completion bash-completion-extras 7 | source /etc/profile.d/bash_completion.sh 8 | 9 | #Disable SELinux 10 | sudo setenforce 0 11 | sudo sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux 12 | 13 | #Disable firewall 14 | sudo systemctl stop firewalld 15 | sudo systemctl disable firewalld 16 | 17 | #Enable IP Forwarding 18 | sudo sysctl -w net.ipv4.ip_forward=1 19 | 20 | -------------------------------------------------------------------------------- /PracticeTest 01/Pod-Example/pod-sample1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: samplepod1 5 | labels: 6 | app: samplepod1 7 | spec: 8 | initContainers: 9 | - name: init-container 10 | image: busybox 11 | command: ['sh', '-c', "echo This-is-init-container"] 12 | containers: 13 | - name: nginx 14 | image: "nginx:latest" 15 | resources: 16 | limits: 17 | cpu: 200m 18 | memory: 50Mi 19 | requests: 20 | cpu: 100m 21 | memory: 20Mi 22 | ports: 23 | - containerPort: 80 24 | name: http 25 | restartPolicy: Always -------------------------------------------------------------------------------- /session05 Kubernetes Services/service-nodeport.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: service-nodeport 5 | spec: 6 | type: NodePort #Loại service: NodePort 7 | selector: #Khai báo rule để lọc các Pod mà service sẽ forward connection tới 8 | app: my-app 9 | apptype: frontend 10 | ports: 11 | - targetPort: 80 #Là port của Pod, service sẽ chuyển tiếp kết nối vào đây 12 | port: 80 #Là port được mở của Service. Client sẽ kết nối với Service qua port 13 | nodePort: 30888 #Port được mở trên tất cả các node để nhận request cho service 14 | -------------------------------------------------------------------------------- /session11 scheduling/deployment-node-selector.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | creationTimestamp: null 5 | labels: 6 | app: my-deployment 7 | name: my-deployment 8 | spec: 9 | replicas: 2 10 | selector: 11 | matchLabels: 12 | app: be 13 | strategy: {} 14 | template: 15 | metadata: 16 | creationTimestamp: null 17 | labels: 18 | app: be 19 | spec: 20 | containers: 21 | - image: nginx 22 | imagePullPolicy: IfNotPresent 23 | name: nginx 24 | resources: {} 25 | nodeSelector: 26 | disktype: ssd 27 | status: {} -------------------------------------------------------------------------------- /PracticeTest 01/ReplicaSet-Example/replicaset-sample3.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: ReplicaSet 3 | metadata: 4 | name: replicaset-sample3 5 | spec: 6 | replicas: 4 7 | selector: 8 | matchLabels: 9 | name: busybox-pod 10 | template: 11 | metadata: 12 | labels: 13 | name: busybox-pod 14 | spec: 15 | containers: 16 | - command: 17 | - sh 18 | - -c 19 | - echo Hello Kubernetes! && sleep 3600 20 | image: busybox777 21 | imagePullPolicy: Always 22 | name: busybox-container 23 | resources: {} 24 | terminationMessagePath: /dev/termination-log -------------------------------------------------------------------------------- /session02-Installation/scripts/update-vm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | network_config="/etc/sysconfig/network-scripts/ifcfg-ens33" 3 | MAC=`cat /sys/class/net/ens33/address` 4 | NAME=$1 5 | IP=$2 6 | 7 | if [ $# -eq 2 ] 8 | then 9 | sudo sed -i "/HWADDR/c\HWADDR=\"$MAC\"" $network_config 10 | sudo sed -i "/IPADDR/c\IPADDR=$IP" $network_config 11 | sudo sed -i "/BOOTPROTO/c\BOOTPROTO=none" $network_config 12 | sudo sed -i "/ONBOOT/c\ONBOOT=yes" $network_config 13 | 14 | sudo sed -i 'd' /etc/hostname 15 | echo "$NAME" |sudo tee /etc/hostname 16 | sudo hostnamectl set-hostname "$NAME" 17 | else 18 | echo "Usage: ./updateNetworkConfig.sh " 19 | fi -------------------------------------------------------------------------------- /session10 configmaps and secrets/pod-configmap-dir.yaml: -------------------------------------------------------------------------------- 1 | #Pod using config file from configmap 2 | apiVersion: v1 3 | kind: Pod 4 | metadata: 5 | name: cm-as-dir 6 | spec: 7 | containers: 8 | - name: env-print-demo 9 | image: busybox 10 | command: ["sh","-c","sleep 365d"] 11 | volumeMounts: 12 | - name: configmap-volume 13 | mountPath: "/app/config" 14 | readOnly: true 15 | volumes: 16 | - name: configmap-volume 17 | configMap: 18 | name: cm-from-dir 19 | items: 20 | - key: "login-policy.conf" 21 | path: "login-policy.conf" 22 | - key: "password-policy.conf" 23 | path: "password-policy.conf" -------------------------------------------------------------------------------- /PracticeTest 01/Deployment-Example/deployment-sample1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: deployment 3 | metadata: 4 | name: deployment-sample1 5 | spec: 6 | replicas: 2 7 | selector: 8 | matchLabels: 9 | name: busybox-deployment 10 | template: 11 | metadata: 12 | labels: 13 | name: busybox-deployment 14 | spec: 15 | containers: 16 | - name: busybox-container 17 | image: busybox 18 | resources: 19 | limits: 20 | cpu: 200m 21 | memory: 50Mi 22 | requests: 23 | cpu: 100m 24 | memory: 20Mi 25 | command: 26 | - sh 27 | - "-c" 28 | - echo Hello Kubernetes! && sleep 3600 29 | -------------------------------------------------------------------------------- /session06 Kubernetes Ingress/ingress-sample/app.ingress.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1 2 | kind: Ingress 3 | metadata: 4 | annotations: 5 | nginx.ingress.kubernetes.io/rewrite-target: / 6 | name: app.prod.viettq.com 7 | spec: 8 | ingressClassName: nginx 9 | rules: 10 | - host: app.prod.viettq.com 11 | http: 12 | paths: 13 | - path: /apple 14 | pathType: Prefix 15 | backend: 16 | service: 17 | name: apple-service 18 | port: 19 | number: 5678 20 | - path: /banana 21 | pathType: Prefix 22 | backend: 23 | service: 24 | name: banana-service 25 | port: 26 | number: 5678 -------------------------------------------------------------------------------- /session11 scheduling/deployment-all-node.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | labels: 5 | app: dp-all-node 6 | name: dp-all-node 7 | spec: 8 | replicas: 3 9 | selector: 10 | matchLabels: 11 | app: dp-all-node 12 | strategy: {} 13 | template: 14 | metadata: 15 | labels: 16 | app: dp-all-node 17 | spec: 18 | containers: 19 | - image: nginx 20 | imagePullPolicy: IfNotPresent 21 | name: nginx 22 | resources: {} 23 | affinity: 24 | podAntiAffinity: 25 | requiredDuringSchedulingIgnoredDuringExecution: 26 | - labelSelector: 27 | matchExpressions: 28 | - key: "app" 29 | operator: In 30 | values: 31 | - "dp-all-node" 32 | topologyKey: kubernetes.io/hostname 33 | status: {} -------------------------------------------------------------------------------- /session11 scheduling/deployment-pod-antiaffinity.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | labels: 5 | app: dp-pod-antiaffinity 6 | name: dp-pod-antiaffinity 7 | spec: 8 | replicas: 4 9 | selector: 10 | matchLabels: 11 | app: demo-pod-antiaffinity 12 | strategy: {} 13 | template: 14 | metadata: 15 | labels: 16 | app: demo-pod-antiaffinity 17 | spec: 18 | containers: 19 | - image: nginx 20 | imagePullPolicy: IfNotPresent 21 | name: nginx 22 | resources: {} 23 | affinity: 24 | podAntiAffinity: 25 | requiredDuringSchedulingIgnoredDuringExecution: 26 | - labelSelector: 27 | matchExpressions: 28 | - key: "app" 29 | operator: In 30 | values: 31 | - "db" 32 | topologyKey: kubernetes.io/hostname 33 | status: {} -------------------------------------------------------------------------------- /session11 scheduling/deployment-pod-affinity.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | creationTimestamp: null 5 | labels: 6 | app: dp-pod-affinity 7 | name: dp-pod-affinity 8 | spec: 9 | replicas: 4 10 | selector: 11 | matchLabels: 12 | app: demo-pod-affinity 13 | strategy: {} 14 | template: 15 | metadata: 16 | creationTimestamp: null 17 | labels: 18 | app: demo-pod-affinity 19 | spec: 20 | containers: 21 | - image: nginx 22 | imagePullPolicy: IfNotPresent 23 | name: nginx 24 | resources: {} 25 | affinity: 26 | podAffinity: 27 | requiredDuringSchedulingIgnoredDuringExecution: 28 | - labelSelector: 29 | matchExpressions: 30 | - key: "app" 31 | operator: In 32 | values: 33 | - "db" 34 | topologyKey: kubernetes.io/hostname 35 | status: {} -------------------------------------------------------------------------------- /session11 scheduling/deployment-node-affinity.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | creationTimestamp: null 5 | labels: 6 | app: lab3-node-affinity 7 | name: lab3-node-affinity 8 | spec: 9 | replicas: 4 10 | selector: 11 | matchLabels: 12 | app: demo-affinity 13 | strategy: {} 14 | template: 15 | metadata: 16 | creationTimestamp: null 17 | labels: 18 | app: demo-affinity 19 | spec: 20 | containers: 21 | - image: nginx 22 | imagePullPolicy: IfNotPresent 23 | name: nginx 24 | resources: {} 25 | affinity: 26 | nodeAffinity: 27 | requiredDuringSchedulingIgnoredDuringExecution: 28 | nodeSelectorTerms: 29 | - matchExpressions: 30 | - key: size 31 | operator: In 32 | values: 33 | - "large" 34 | - "medium" 35 | status: {} -------------------------------------------------------------------------------- /PracticeTest 01/Deployment-Example/deployment-sample2.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: apps/v1 3 | kind: Deployment 4 | metadata: 5 | name: deployment-sample2 6 | spec: 7 | replicas: 2 8 | selector: 9 | matchLabels: 10 | name: nginx-deployment 11 | template: 12 | metadata: 13 | labels: 14 | name: nginx-deployment 15 | spec: 16 | containers: 17 | - name: nginx-container 18 | image: nginx 19 | ports: 20 | - containerPort: 80 21 | name: http 22 | 23 | --- 24 | apiVersion: apps/v1 25 | kind: Deployment 26 | metadata: 27 | name: deployment-sample3 28 | spec: 29 | replicas: 2 30 | selector: 31 | matchLabels: 32 | name: busybox-deployment 33 | template: 34 | metadata: 35 | labels: 36 | name: busybox-deployment 37 | spec: 38 | containers: 39 | - name: busybox-container 40 | image: busybox 41 | command: 42 | - sh 43 | - "-c" 44 | - echo Hello Kubernetes! && sleep 3600 -------------------------------------------------------------------------------- /session10 configmaps and secrets/practice-configmap-secret.txt: -------------------------------------------------------------------------------- 1 | #Practice 2 | 3 | #Configmap 4 | #Create configmap from literal 5 | kubectl -n cfg create configmap cm-literal --from-literal=author=viettq --from-literal=price=50 6 | 7 | #Create configmap from file 8 | #create config-file 9 | cat <> cm-file 10 | > author=viettq 11 | > price=50 12 | > EOF 13 | #create configmap from config-file 14 | kubectl -n cfg create configmap cm-from-file --from-file=cm-file 15 | 16 | #Create configmap from folder 17 | #create folder and config-file in folder 18 | mkdir configmap-dir 19 | cd config-map-dir 20 | cat <> login-policy.conf 21 | > lock_after=5 22 | > lock_time=60 23 | > EOF 24 | cat <> password-policy.conf 25 | > password_length=8 26 | > expire_day=30 27 | > special_character=true 28 | > EOF 29 | #create configmap from directory 30 | kubectl -n cfg create configmap cm-from-dir --from-file=configmap-dir 31 | 32 | #Create Pod using configmap 33 | #Pod using configmap value as variable 34 | print env in pod 35 | #Pod using configmap as volume and config file 36 | Cat config-file in Pod 37 | Edit configmap --> verify value is updated to config-file in Pod 38 | 39 | -------------------------------------------------------------------------------- /session03-node and pods/session3-tasks.txt: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | kubectl run pod-curl --image=busybox --dry-run=client -oyaml -- /bin/sh -c 'sleep 100' > curl-pod.yaml 4 | 5 | 6 | #Task1: Create a new pod named "curly" with following information and check if it is running 7 | kubectl run -it curly --image=curlimages/curl -- sh 8 | 9 | #Task 2: Check the curly pod status 10 | #Task 3: Delete the curly pod and verify the status 11 | #Task 4: Create curly pod again but add more two labels: app=curl and apptype=tool. Verify the labels are set to pod 12 | kubectl run -it curly --image=curlimages/curl -- sh 13 | 14 | 15 | #Task 5: Create the pod named "nginx-pod" with image "nginxlatest" by using dry-run to get yaml file and apply to k8s 16 | #Check the pod status --> It should be "ErrImagePull" 17 | #Edit Pod "nginx-pod" to change the image from "nginx-latest" to "nginx" --> Verify the status (should be running) 18 | 19 | #Task 6: Find IP of Pod "nginx-pod" 20 | #From any node try this command: curl http::80 and verify the result 21 | #Attach to curly pod and try this command: curl http::80 and verify the result 22 | kubectl attach curly6 -i -t 23 | curl http://10.42.0.27:80 24 | 25 | #Task 7: Create a new Pod named "nginx-multi" with 2 containers. 26 | #First Container: named "nginx", image=nginx, port=80 27 | #Second Container: named "curl", image=curlimages/curl 28 | #With 2 labels: app=nginx apptype=webapp 29 | 30 | -------------------------------------------------------------------------------- /session10 configmaps and secrets/pod-configmap-env.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: print-configmap-new 5 | spec: 6 | containers: 7 | - name: env-print-demo 8 | image: busybox 9 | env: 10 | - name: APPNAME 11 | valueFrom: 12 | configMapKeyRef: 13 | name: myapp-config 14 | key: app_name 15 | - name: WELCOMETEXT 16 | valueFrom: 17 | configMapKeyRef: 18 | name: myapp-config 19 | key: welcome_text 20 | command: ["sh","-c","echo appname=$(APPNAME) welcome=$(WELCOMETEXT);sleep 365d"] 21 | 22 | --- 23 | apiVersion: v1 24 | kind: Pod 25 | metadata: 26 | name: cm-as-env 27 | spec: 28 | containers: 29 | - name: env-print-demo 30 | image: busybox 31 | env: 32 | - name: AUTHOR 33 | valueFrom: 34 | configMapKeyRef: 35 | name: cm-from-literal 36 | key: author 37 | - name: AGE 38 | valueFrom: 39 | configMapKeyRef: 40 | name: cm-from-literal 41 | key: age 42 | command: ["sh","-c","echo author=$(AUTHOR) welcome=$(AGE);sleep 365d"] 43 | 44 | --- 45 | apiVersion: v1 46 | kind: Pod 47 | metadata: 48 | name: cm-file-as-env 49 | spec: 50 | containers: 51 | - name: configmap-example-busybox 52 | image: k8s.gcr.io/busybox 53 | command: [ "/bin/sh", "-c", "env" ] 54 | envFrom: 55 | # Load the Complete ConfigMap 56 | - configMapRef: 57 | name: tv 58 | restartPolicy: Never -------------------------------------------------------------------------------- /session02-Installation/installation-server/configure-kubespray.sh: -------------------------------------------------------------------------------- 1 | #update hostfile for installation server 2 | echo "192.168.10.11 master1" |sudo tee -a /etc/hosts 3 | echo "192.168.10.12 worker1" |sudo tee -a /etc/hosts 4 | echo "192.168.10.13 worker2" |sudo tee -a /etc/hosts 5 | 6 | cd ~ 7 | mkdir kubernetes_installation/ 8 | 9 | #install & configure docker on installation server 10 | sudo yum update -y 11 | curl -fsSL https://get.docker.com/ | sh 12 | sudo usermod -aG docker sysadmin 13 | 14 | #download kubespray 15 | git clone https://github.com/kubernetes-sigs/kubespray.git --branch release-2.16 16 | cd /home/sysadmin/kubernetes_installation/kubespray 17 | cp -rf inventory/sample inventory/viettq-cluster 18 | 19 | #configure your cluster before installation 20 | cd /home/sysadmin/kubernetes_installation/kubespray/ 21 | cd inventory/viettq-cluster 22 | 23 | #This must be done manually 24 | #vi host.yaml 25 | 26 | #Change network CNI plugin to flannel 27 | cd /home/sysadmin/kubernetes_installation/kubespray/ 28 | sed -i "/kube_network_plugin:/c\kube_network_plugin: flannel" inventory/viettq-cluster/group_vars/k8s_cluster/k8s-cluster.yml 29 | 30 | #Run this command to create kubespray container and exec into it 31 | #docker run --rm -it --mount type=bind,source=/home/sysadmin/kubernetes_installation/kubespray/inventory/viettq-cluster,dst=/inventory \ 32 | quay.io/kubespray/kubespray:v2.16.0 bash 33 | 34 | #run this command inside to newly created container above 35 | #ansible-playbook -i /inventory/hosts.yaml cluster.yml --user=sysadmin --ask-pass --become --ask-become-pass 36 | -------------------------------------------------------------------------------- /session04 Deployment and replicaset/note.txt: -------------------------------------------------------------------------------- 1 | #List deployment 2 | kubectl get deployments.apps [-n namespace] 3 | kubectl get deployments.apps -n demo 4 | 5 | #get deployment info 6 | kubectl get deployments.apps [deployment] -oyaml [-n namespace] 7 | kubectl get deployments.apps node-app-deployment -oyaml -n demo 8 | 9 | kubectl describe deployments [deployment] [-n namespace] 10 | kubectl describe deployments node-app-deployment -n demo 11 | 12 | #update deployment 13 | kubectl set image deployment [deployment] [container]=[image:tag] [-n namespace] 14 | kubectl set image deployment node-app-deployment node-app=myapp:v2.0 -n demo 15 | 16 | #rollout history of deployment 17 | kubectl rollout history deployment [deployment] [-n namespace] 18 | kubectl rollout history deployments node-app-deployment -n demo 19 | 20 | #rollback a deployment using set image 21 | kubectl set image deployment [deployment] [container]=[image:tag] [-n namespace] 22 | kubectl -n demo set image deployment node-app-deployment node-app=harbor.prod.viettq.com/demo/myapp:v2.0 -n demo 23 | 24 | #rollback a deployment using deployment history 25 | kubectl rollout history deployment [deployment] [-n namespace] --revision=[number] 26 | kubectl rollout history deployment/node-app-deployment --revision=1 27 | kubectl rollout undo deployment/node-app-deployment --to-revision=1 -n demo 28 | 29 | #verify deployment status 30 | kubectl rollout status deployment [deployment] [-n namespace] 31 | kubectl rollout status deployment node-app-deployment -n demo 32 | 33 | #restart deployment 34 | kubect rollout restart deployment [deployment] [-n namespace] 35 | kubect rollout restart deployment node-app-deployment -n demo 36 | 37 | #scale deployment 38 | kubectl scale deployment [deployment] --replicas=[number] [-n namespace] 39 | kubectl scale deployment node-app-deployment --replicas=10 -n demo 40 | -------------------------------------------------------------------------------- /session11 scheduling/session 11 Practice.yml: -------------------------------------------------------------------------------- 1 | #Scheduling practice 2 | 3 | #Lab1: Node Selector 4 | #Require at least 2 worker node: node1, node2 5 | #label your node: 6 | kubectl label node node1 size=small 7 | kubectl label node node2 size=medium 8 | kubectl label node node3 size=large 9 | 10 | kubectl label node node1 disktype=ssd 11 | kubectl label node node2 disktype=ssd 12 | kubectl label node node3 disktype=hdd 13 | 14 | #Create a pod "my-nginx" using image "nginx" and schedule that pod on node which have label "disktype=ssd" 15 | #hint: pod-node-selector.yaml 16 | 17 | 18 | #Create a deployment "my-deployment" using image "nginx" with 2 replicas and shedule its pods on node which have label "disktype=ssd". 19 | #The Pods in the deployment should have label "app=be" 20 | #hint: deployment-node-selector.yaml 21 | #Check where are the pods scheduled? 22 | #Scale the deployment to 10 replicas and check where are the pod scheduled? 23 | kubectl scale deployment my-deployment --replicas 10 24 | 25 | 26 | #LAB2: Taint and toleration 27 | #prerequisite: Delete all pods/deployments from previous lab 28 | #Taint for node1 29 | kubectl taint node node1 app=special:NoSchedule 30 | #Task1 31 | #Create a Pod "pod-no-toleration" with image "nginx" and schedule that pod on node1 32 | #hint: pod-no-toleration.yaml 33 | 34 | #Task2 35 | #Create a Pod "pod-no-toleration" with image "nginx" and add toleration to make sure it is scheduled on node1 36 | #hint pod-with-toleration.yaml 37 | 38 | 39 | #LAB3: Node Affinity 40 | #prerequisite: Delete all pods/deployments from previous lab 41 | #label your node if not exists: 42 | kubectl label node node1 size=small 43 | kubectl label node node2 size=medium 44 | kubectl label node node3 size=large 45 | 46 | kubectl label node node1 disktype=ssd 47 | kubectl label node node2 disktype=ssd 48 | kubectl label node node3 disktype=hdd 49 | 50 | #Task1 51 | #Create a deployment named "lab3-node-affinity" with image "nginx" and replicas=4 52 | #Using label/selector with app=demo-affinity 53 | #Make sure theses Pod do not run on nodes which have label "size=small" 54 | #NOTE: untaint all worker node if taint exists 55 | #kubectl taint node node1 app=special:NoSchedule- 56 | #hint: deployment-node-affinity.yaml 57 | 58 | #LAB4 PodAffinity/PodAntiAffinity 59 | #prerequisite: Delete all pods/deployments from previous lab 60 | #Task1 PodAffinity 61 | #create a Pod with label "app=db" on node1 - pod-db-node1.yaml 62 | #create a deployment named "dp-pod-affinity" using image "nginx" with replicas=5 using label/selector "app=demo-pod-affinity" 63 | #make sure its pods only run on node which have existing Pod with label "app=db" 64 | #hint: deployment-pod-affinity.yml 65 | 66 | #Task2 67 | #Delete Pod/deployment from previous lab 68 | #create a Pod with label "app=db" on node1 - pod-db-node1.yaml 69 | #create a deployment named "dp-pod-antiaffinity" using image "nginx" with replicas=5 using label/selector "app=demo-pod-antiaffinity" 70 | #make sure its pods only run on node which DO NOT have existing Pod with label "app=db" 71 | #hint: deployment-pod-antiaffinity.yml 72 | #scale replicas=10 and verify where the pods are scheduled 73 | 74 | #Task3 75 | #Delete all Pods/deployments from previous lab 76 | #create a deployment named "dp-pod-antiaffinity-new" using image "nginx" and make sure each node has exactly 1 Pod from this deployment 77 | #hint deployment-all-node.yaml 78 | 79 | --------------------------------------------------------------------------------