https://segmentfault.com/a/1190000021380185
kubectl get pod --sort-by .metadata.name
题目一般都是按名字排序
kubectl logs heapster-798fcd9949-lk9rc | grep error > xx.txt
要求是把错误内容输出到某个文件中,可以粘贴,也可以直接重定向文件
命令行创建pod的方法可以参考攻略的pdf,主要参数是--restart=Never,否则就会是deployment
kubectl run nginx-pod --image=nginx --port=80 --restart=Never --dry-run -o yaml > pod.yaml
先导出一份示例yaml出来,记得保存好这份yaml,后面也要用的
在yaml的spec属性中增加 nodeName: xxx
创建pod:kubectl create -f pod.yaml
kubectl get node
如何判断正常节点:一般都是not ready
get或者describe node排查node信息,把可用数写到一个文件中,文件里写一个数字就行了,不要多写空格换行之类的,谨记
直接使用这个文档的示例就行,不用改啥东西
文档地址:https://kubernetes.io/docs/concepts/storage/volumes/
文档地址:https://kubernetes.io/docs/co...
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: nginx-pod
name: nginx-pod
spec:
containers:
- image: nginx
name: nginx-pod
command: ['sh','-c','if [ -f "a.txt" ]; then echo xx ;fi']
ports:
- containerPort: 80
resources: {}
volumeMounts:
- name: workdir
mountPath: /usr/nginx/html
dnsPolicy: ClusterFirst
initContainers:
- image: busybox
name: initcheck
command: ['sh','-c','touch /tmp/index.html']
volumeMounts:
- name: workdir
mountPath: /tmp
volumes:
- name: workdir
emptyDir: {}
pod的模板使用前几题留下的yaml,改下就行了
service的nodePort类型:https://kubernetes.io/docs/concepts/services-networking/service/
注意:校验nodePort是否通,不要在中控机上校验,登录到node去校验
也有可能让你建cluster-ip类型
apiVersion: v1
kind: Pod
metadata:
name: demo
spec:
containers:
- image: nginx
name: nginx
- image: redis
name: redis
按selector查找
kubectl get pod --selector="run=demo" | awk '{ print $1}' | grep -v NAME |
或者找到pod后,一个一个看
kubectl top pod | grep -v NAME | sort -k 3
文档地址:https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/
文档中给的yaml内容太多了,volume都可以删掉
daemonset创建好后会发现pod数小于节点数,可以看下节点是不是打了taint
kubectl scale --replicas=4 deployment demo
这个文档里面全都有,记住链接
https://kubernetes.io/docs/concepts/configuration/secret/
升级
kubectl set image deployments demo demo=nginx:1.11 --record
回滚
kubectl rollout undo deployment demo
service和pod的创建用之前的yaml
查看dns
kubectl run -it --image busybox:1.28.4 dnstest --rm /bin/sh
sevice:
nslookup svc-demo.kube-system.svc.cluster.local
pod:
nslookup 1-2-3-4.default.pod.cluster.local
查看pod ip时,要把1.2.3.4换成1-2-3-4,否则会报错
对应的文档:https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/
ETCDCTL_API=3 etcdctl --endpoints ....snapshot save xxx 根据-h提示写就行了
先声明环境变量ETCDCTL_API=3 ,不然etcdctl 是v2版本
这个文档:
文档地址:https://kubernetes.io/docs/tasks/administer-cluster/configure-upgrade-etcd/
文档地址:https://kubernetes.io/docs/tasks/administer-cluster/static-pod/
找到--pod-manifest-path=/etc/kubelet.d/配置的位置,然后把pod的yaml放进去
apiVersion: v1
kind: Pod
metadata:
name: static-web
labels:
role: myrole
spec:
containers:
- name: web
image: nginx
ports:
- name: web
containerPort: 80
protocol: TCP
先创建ns,在创建pod,和前面步骤类似
文档地址:
https://kubernetes.io/docs/concepts/storage/persistent-volumes/
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
env: test
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
nodeSelector:
disktype: ssd
22.排查apiserver连接不上问题:
用的kubeadmin安装的,是kubelet的配置中目录地址有问题
应该是直接drain,需要注意daemonset要强制删除,或者给节点打污点,taint,再去删掉