首页 > 其他分享 >Kubernetes学习笔记(三十九):KodeKloud练习题(一)

Kubernetes学习笔记(三十九):KodeKloud练习题(一)

时间:2022-10-15 20:55:05浏览次数:57  
标签:练习题 node Kubernetes kubectl controlplane nginx secret KodeKloud root

  1. Question

Upgrade the current version of kubernetes from 1.23.0 to 1.24.0 exactly using the kubeadm utility. Make sure that the upgrade is carried out one node at a time starting with the controlplane node. To minimize downtime, the deployment gold-nginx should be rescheduled on an alternate node before upgrading each node.

Upgrade controlplane node first and drain node node01 before upgrading it. Pods for gold-nginx should run on the controlplane node subsequently.

Details

  • Cluster Upgraded?
  • pods 'gold-nginx' running on controlplane?

Solution

Here is the solution for this task. Please note that the output of these commands have not been added here.

On the controlplane node:

root@controlplane:~# kubectl drain controlplane --ignore-daemonsets
root@controlplane:~# apt update
root@controlplane:~# apt-get install kubeadm=1.24.0-00
root@controlplane:~# kubeadm upgrade plan v1.24.0
root@controlplane:~# kubeadm upgrade apply v1.24.0
root@controlplane:~# apt-get install kubelet=1.24.0-00
root@controlplane:~# systemctl daemon-reload
root@controlplane:~# systemctl restart kubelet
root@controlplane:~# kubectl uncordon controlplane

Before draining node01, we need to remove the taint from the controlplane node.

# Identify the taint first. 
root@controlplane:~# kubectl describe node controlplane | grep -i taint

# Remove the taint with help of "kubectl taint" command.
root@controlplane:~# kubectl taint node controlplane node-role.kubernetes.io/control-plane:NoSchedule-

# Verify it, the taint has been removed successfully.  
root@controlplane:~# kubectl describe node controlplane | grep -i taint

Now, drain the node01 as follows: -

root@controlplane:~# kubectl drain node01 --ignore-daemonsets

SSH to the node01 and perform the below steps as follows:

root@node01:~# apt update
root@node01:~# apt-get install kubeadm=1.24.0-00
root@node01:~# kubeadm upgrade node
root@node01:~# apt-get install kubelet=1.24.0-00
root@node01:~# systemctl daemon-reload
root@node01:~# systemctl restart kubelet

To exit from the specific node, type exit or logout on the terminal.

Back on the controlplane node:

root@controlplane:~# kubectl uncordon node01
root@controlplane:~# kubectl get pods -o wide | grep gold (make sure this is scheduled on node)
  1. Question

Print the names of all deployments in the admin2406 namespace in the following format:
DEPLOYMENT CONTAINER_IMAGE READY_REPLICAS NAMESPACE
<deployment name> <container image used> <ready replica count> <Namespace>
. The data should be sorted by the increasing order of the deployment name.

Example:
DEPLOYMENT CONTAINER_IMAGE READY_REPLICAS NAMESPACE
deploy0 nginx:alpine 1 admin2406
Write the result to the file /opt/admin2406_data.

Details

  • Task completed?

Solution

Run the below command to get the correct output:

kubectl -n admin2406 get deployment -o custom-columns=DEPLOYMENT:.metadata.name,CONTAINER_IMAGE
  1. Question

A kubeconfig file called admin.kubeconfig has been created in /root/CKA. There is something wrong with the configuration. Troubleshoot and fix it.

Details

  • Fix /root/CKA/admin.kubeconfig

Solution

Make sure the port for the kube-apiserver is correct. So for this change port from 4380 to 6443.

Run the below command to know the cluster information:

kubectl cluster-info --kubeconfig /root/CKA/admin.kubeconfig
  1. Question

Create a new deployment called nginx-deploy, with image nginx:1.16 and 1 replica. Next upgrade the deployment to version 1.17 using rolling update.

Details

  • Image: nginx:1.16
  • Task: Upgrade the version of the deployment to 1:17

Solution

Make use of the kubectl create command to create the deployment and explore the --record option while upgrading the deployment image.

Run the below command to create a deployment nginx-deploy:

kubectl create deployment  nginx-deploy --image=nginx:1.16

Run the below command to update the new image for nginx-deploy deployment and to record the version:

kubectl set image deployment/nginx-deploy nginx=nginx:1.17 --record
  1. Question

A new deployment called alpha-mysql has been deployed in the alpha namespace. However, the pods are not running. Troubleshoot and fix the issue. The deployment should make use of the persistent volume alpha-pv to be mounted at /var/lib/mysql and should use the environment variable MYSQL_ALLOW_EMPTY_PASSWORD=1 to make use of an empty root password.

Important: Do not alter the persistent volume.

Details

  • Troubleshoot and fix the issues

Solution

Use the command kubectl describe and try to fix the issue.
Solution manifest file to create a pvc called mysql-alpha-pvc as follows:

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-alpha-pvc
  namespace: alpha
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: slow
  1. Question

Take the backup of ETCD at the location /opt/etcd-backup.db on the controlplane node.

Details

  • Troubleshoot and fix the issues

Solution

Take a help of command etcdctl snapshot save --help options.

export ETCDCTL_API=3
etcdctl snapshot save --cacert=/etc/kubern
  1. Question

Create a pod called secret-1401 in the admin1401 namespace using the busybox image. The container within the pod should be called secret-admin and should sleep for 4800 seconds.

The container should mount a read-only secret volume called secret-volume at the path /etc/secret-volume. The secret being mounted has already been created for you and is called dotfile-secret.

Details

  • Pod created correctly?

Solution

Use the command kubectl run to create a pod definition file. Add secret volume and update container name in it.
Alternatively, run the following command:

kubectl run secret-1401 -n admin1401 --image=busybox --dry-run=client -oyaml --command -- sleep 4800 > admin.yaml

Add the secret volume and mount path to create a pod called secret-1401 in the admin1401 namespace as follows:

---
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: secret-1401
  name: secret-1401
  namespace: admin1401
spec:
  volumes:
  - name: secret-volume
    # secret volume
    secret:
      secretName: dotfile-secret
  containers:
  - command:
    - sleep
    - "4800"
    image: busybox
    name: secret-admin
    # volumes' mount path
    volumeMounts:
    - name: secret-volume
      readOnly: true
      mountPath: "/etc/secret-volume"

标签:练习题,node,Kubernetes,kubectl,controlplane,nginx,secret,KodeKloud,root
From: https://www.cnblogs.com/Bota5ky/p/16795015.html

相关文章

  • 【 云原生 | kubernetes 】资源对象 - 容器化守护进程之Daemonset
    DaemonSet简述DaemonSet对象确保所有(或部分)节点运行一个Pod的副本。随着节点被添加到集群中,Pods也被添加到集群中。当节点从集群中移除时,这些Pods将被垃圾收集。删除一......
  • 练习题06List
    分析以下需求,并用代码实现:(1)有如下代码:(2)定义方法统计集合中指定元素出现的次数,如"a"3,"b"2,"c"1List<String>list=newArrayList<>();list.add("a");list.......
  • kubernetes学习笔记3资源清单
    kubernetes对象:​pod|service|replicaset|deployment|statefulset|daemonset|job|cronjob​服务发现及均衡,service|ingress​配置与存储,volume|CSI|ComfigMap|Secret|Downwa......
  • 在 Kubernetes 中实现微服务应用监控
    张坚,科大讯飞开发工程师,云原生爱好者。本篇文章我们基于Prometheus和Grafana实现微服务应用监控。KubeSphere平台本身提供了监控功能,包括节点状态、集群资源使......
  • Mounting Kubernetes config map as single file returns error: "caused: mount thro
    原因是k8s的configmap不能挂载文件,只能挂载文件夹本来以为自己的挂载的是文件夹后面发现docker打包时添加文件命令文件夹没有加"/"导致被打成文件了add./index.html......
  • Kubernetes入门宝典
    docker基础在线安装1、docker安装centos7sudoyumremovedocker\docker-client\docker-client-latest\......
  • Kubernetes--Ingress资源类型
    Ingress资源类型基于HTTP暴露的每个Service资源均可发布于一个独立的FQDN主机名之上,如“www.ik8s.io”;也可发布于某主机上的URL路径之上,从而将它们整合到同一个Web站......
  • create a kubernetes CRD
    installpackage  pip3installjinja2pip3installyq FunctionforJinja2Render  justpastethefollowcodetoyourterminaljinji2_render(){yf=$1......
  • 【C++从入门到熟练练习题】000 VS2015新建程序及输出Hello World
    一、前言大学很多计算机相关专业的基础课都会有C++,C++是比较经典的编程语言,编程语言一定不是看出来的,而是敲代码敲出来的。所以会给大家不定期分享一些C++练习题。在下一次......
  • 练习题02
    用程序判断2022年7月27日是星期几?使用SimpleDateFormat类,把2018-03-04转换成2018年03月04日创建一个表示从1970年1月1日0时0分1秒的Date类的对象,并获取该对象到1970年1......