英语段落摘抄source<(kubectl completion bash)
●1.Set configuration context$kubectl config u-context k8s
Monitor the logs of Pod foobar and Extract log lines corresponding to error unable-to-access-website Write them to
/opt/KULM00201/foobar
监控foobar Pod的日志,提取unable-to-access-website相应的行写入到/opt/KULM00201/foobar文件中
解答:
#kubectl logs foobar|grep‘unable-to-access-website’>/opt/KULM00201/foobar
备注:
撤销taint
kubectl taint node vms51.rhce node-role.kubernetes.io/master-
●2.Set configuration context$kubectl config u-context k8s
List all PVs sorted by name,saving the full kubectl output to/opt/KUCC0010/my_volumes.
U kubectl own functionally for sorting the output,and do not manipulate it any further.
使用name排序列出所有的PV,把输出内容存储到/opt/KUCC0010/my_volumes文件中
使用kubectl own对输出进行排序,并且不再进一步操作它。
解答:
#kubectl get pv--all-namespaces--sort-by={.metadata.name}>/opt/KUCC0010/my_volumes
●3.Set configuration context$kubectl config u-context k8s
Ensure a single instance of Pod nginx is running on each node of the Kubernetes cluster where nginx also reprents the image name which has to be ud.Do no override any taints currently in place.
U Daemont to complete this task and u ds.kusc00201as Daemont name.
确保在kubectl集群的每个节点上运行一个Nginx Pod。其中Nginx Pod必须使用Nginx镜像。不要覆盖
当前环境中的任何traints。
使用Daemont来完成这个任务,Daemont的名字使用ds.kusc00201。
引用:Concepts->Workloads->Controllers->DaemonSet
解答:
#cat ds.kusc00201.yaml
apiVersion:apps/v1
kind:DaemonSet
metadata:
name:ds.kusc00201
namespace:default
labels:
k8s-app:ds.kusc00201
戒烟的危害spec:
lector:
matchLabels:
name:ds.kusc00201
template:
metadata:
labels:
name:ds.kusc00201
spec:
containers:
-
name:nginx
image:nginx
#kubectl apply-f ds.kusc00201
●4.Set configuration context$kubectl config u-context k8s
Perform the following tasks
学习棒
Add an init container to lumpy-koala(which has been defined in spec file/opt/kucc00100/pod-spec-KUCC00100.yaml)
The init container should create an empty file named/If/ is not detected,the Pod should exit Once the spec file has been updated with the init container definition,the Pod should be created.
添加一个initcontainer到lumpy-koala
这个initcontainer应该创建一个名为/的空文件,如果/没有被检测到,这个Pod应该更新spec文件并退出,这个Pod应该被创建
引用:Task->Configure Pod and Containers->Configure Pod Initialization(Create a Pod that has an Init Container) Task->Configure Pod and Containers->Configure Liveness and Readiness Probes(Define a liveness command)
解答:
基础环境:
apiVersion:v1
kind:Pod
metadata:
name:myapp-pod
labels:
app:myapp
spec:
containers:
-name:myapp-container
image:nginx
volumeMounts:
-name:workdir
mountPath:/workdir
livenessProbe:
exec:
command:
-cat
-/
initContainers:
-name:install
image:busybox
command:
-touch
-/
volumeMounts:
-name:workdir
mountPath:/workdir
volumes:
-name:workdir
emptyDir:{}
#kubectl apply-f pod-basic.yaml
备注:
1.在外层容器上挂载目录,不然无法识别,
2.添加livenessprobe监测文件是否存在信息
3.添加initContainer
●5.Set configuration context$kubectl config u-context k8s
Create a pod named kucc4with a single container for each of the following images running inside(there may be between1and 4images specified):nginx+redis+Memcached+consul
创建一个名为kucc4的Pod,其中内部运行着nginx+redis+memcached+consul4个容器
引用:Concepts->Workloads->Pods->Pod Overview
找到创建pod的例子,修改添加container的内容
解答:
大学生毕业时间#cat kucc4.yaml
apiVersion:v1
林汉达简介
kind:Pod
metadata:
name:kucc4
labels:
app:kucc4
spec:
containers:
-name:nginx
image:nginx
-name:redis
image:redis
-name:memcached
image:memcached
-name:consul
image:consul
#kubectl apply-f kucc4.yaml
●6.Set configuration context$kubectl config u-context k8s
Schedule a Pod as follows:
Name:nginx-kusc00101
Image:nginx
Node lector:disk=ssd
创建Pod,名字为nginx-kusc00101,镜像为nginx,存放在label为disk=ssd的node上引用:Concepts->Configuration->Assigning Pods to Nodes
解答:
#cat nginx-kusc00101.yaml
apiVersion:v1
kind:Pod
metadata:
name:nginx-kusc00101
labels:
env:test
spec:
元曲简介
containers:
-name:nginx
image:nginx
nodeSelector:
disk:ssd
#kubectl apply-f nginx-kusc00101.yaml
备注:
给node添加label
kubectl label node vms52.rhce disk=ssd
给node取消label
kubectl label node vms52.rhce disk-
Create a deployment as follows
Name:nginx-app
Using container nginx with version1.11.9-alpine
The deployment should contain3replicas
Next,deploy the app with new version1.12.0-alpine by performing a rolling update and record that update.
Finally,rollback that update to the previous version1.11.9-alpine.
创建deployment
名字为nginx-app
容器采用1.11.9版本的nginx
这个deployment包含3个副本
接下来,通过滚动升级的方式更新镜像版本为1.12.0,并记录这个更新
最后,回滚这个更新到之前的1.11.9版本
解答:
#kubectl run nginx-app--image=nginx:1.11.9--replicas=3--record
#kubectl t image deployment nginx-app nginx-app=nginx:1.12.0--record
#kubectl rollout history deployment nginx-app
#kubectl rollout undo deployment nginx-app--to-revision=1
备注:
kubectl rollout pau deployment nginx-app暂停deployment,不记入history
kubectl rollout resume deployment nginx-app恢复deployment重新记入history
●8.Set configuration context$kubectl config u-context k8s
Create and configure the rvice front-end-rvice so it’s accessible through NodePort/ClusterIp and routes to the existing pod named front-end.
创建和配置rvice,名字为front-end-rvice。可以通过NodePort/ClusterIp开访问,并且路由到front-end的Pod上解答:
#kubectl expo pod front-end--name=front-end-rvice--type="NodePort"--port=80
●9.Set configuration context$kubectl config u-context k8s
Create a Pod as follows:
Name:jenkins
Using image:jenkins
In a new Kubernetes namespace named website-frontend
创建一个Pod,名字为Jenkins,镜像使用Jenkins。在新的namespace website-frontend上创建
引用:Concepts->Workloads->Pods->Pod Overview
解答:
#kubectl create ns website-frontend
apiVersion:v1
kind:Pod
metadata:
name:jenkins
labels:
app:jenkins
spec:
containers:
-name:jenkins
image:jenkins
#kubectl apply-f jenkins.yaml-n website-frontend
Create a deployment spec file that will:
Launch7replics of the redis image with the label:app_enb_stage=dev
Deployment name:kual00201
Save a copy of this spec file to/opt/KUAL00201/deploy_spec.yaml(or.json)
When you are done,clean up(delete)any new k8s API objects that you produced during this task
创建deployment的spec文件:
使用redis镜像,7个副本,label为app_enb_stage=dev
划粥断齑deployment名字为kual00201
保存这个spec文件到/opt/KUAL00201/deploy_spec.yaml
完成后,清理(删除)在此任务期间生成的任何新的k8s API对象
意乙联赛解答:
#kubectl run kual00201--image=redis--replicas=7--labels="app_enb_stage=dev"--dry-run-o yaml>
/opt/KUAL00201/deploy_spec.yaml
●11.Set configuration context$kubectl config u-context k8s
Create a file/opt/ that lists all pods that implement Service foo in Namespace production.
The format of the file should be one pod name per line.
创建一个文件/opt/,这个文件列出所有的rvice为foo,在namespace为production的Pod 这个文件的格式是每行一个Pod
解答:
#kubectl get svc--show-labels-n production
#kubectl get pods-l name=lable-xxx1-n production|grep-v NAME|awk‘{print$1}’>>/opt/ 备注:
●12.Set configuration context$kubectl config u-context k8s
Create a Kubernetes Secret as follows:
Name:super-cret
Credential:alice or urname:bob
Create a Pod named pod-crets-via-file using the redis image which mounts a cret named super-cret at/crets Create a cond Pod named pod-crets-via-env using the redis image,which exports credential/urname as TOPSECRET/CREDENTIALS
备注:Concepts->Configuration->Secrets
解答:
#echo-n'bob'|ba64
Ym9i
#cat cret.yaml
apiVersion:v1
kind:Secret
metadata:
name:super-cret
type:Opaque
data:
urname:Ym9i
#cat pod-cret-via-file.yaml
apiVersion:v1
kind:Pod
metadata:
name:pod-cret-via-file
spec: