目录
💟这里是CS大白话专场,让枯燥的学习变得有趣!
💟没有对象不要怕,我们new一个出来,每天对ta说不尽情话!
💟好记性不如烂键盘,自己总结不如收藏别人!
🧡Ingress
创建一个Ingress满足:
名字:pong
命名空间:ing-internal
在路径/hi上使用端口5678暴露服务 hi
vim ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: pong
namespace: ing-internal
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- http:
paths:
- path: /hi
pathType: Prefix
backend:
service:
name: hi
port:
number: 5678
kubectl apply -f ingress.yaml
🧡pod
🍠扩容
扩容名为loadbalancer的deployment的pods数为6。
kubectl scale --replicas=6 deployment loadbalancer
🍠调度
分配一个pod:
名字:nginx-kusc00401
镜像:nginx
节点选择:disk=spinning
vim pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-kusc00401
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
nodeSelector:
disk: spinning
kubectl apply -f pod.yaml
🍠镜像
创建一个名为kucc1的pod,使用以下镜像(可能包含1-4):nginx+redis+memcached+consul。
kubectl run kucc1 --image=nginx --dry-run=client -o yaml > kucc1.yaml
vim kucc1.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp:null
labels:
run:kucc1
name: kucc1
spec:
containers:
- image: nginx
name: nginx
resources: {}
- image: redis
name: redis
resources: {}
- image: memchached
name: memcached
resources: {}
- image: consul
name: consul
resources: {}
dnsPolicy: ClusterFirst
kubectl apply -f kucc1.yaml
🍠监控
监控名为foobar的pod的日志:
提取与错误unable-to-access-website相对应的日志行
将这些日志行写入/opt/KUTR00101/foobar
kubectl logs foobar | grep unable-access-website > /opt/KUTR00101/foobar
通过pod标签name=cpu-user,找到运行时占用高CPU的pods,并将占用CPU最高的pod名字写入到文件/opt/KUTR000401/KUTR00401.txt。
kubectl top pods -A -l name=cpu-user --sort-by='cpu'
echo "name" > /opt/KUTR00401/KUTR00401.txt
🧡node
检查集群中有多少Ready节点(不包含NoSchedule污点的节点)。
kubectl get node | grep ready
kubectl describe node | grep Taint | grep NoSchedule
将数目x写到/opt/KUSC00402/kusc00402.txt。
echo x > /opt/KUSC00402/kusc00402.txt