k8s
一.环境搭建
参考地址 :
https://www.cnblogs.com/tz90/p/15466646.html
#最新、最全、最详细的 K8S 学习笔记总结(2021最新版)
https://www.jianshu.com/p/2cbdf5b65bb7
二.命令
命令自动补全:
[root@k8s-master01 ~]
[root@k8s-master01 ~]
[root@k8s-master01 ~]
[root@k8s-master01 ~]
1.查看类常用命令
kubeadm join 192.168.56.12:6443 --token qj0nng.wmfof5ego8i5bx5f --discovery-token-ca-cert-hash sha256:ed86c67741198cf7da9a8775db01672d00dfa6833d3e9059adb3ebdff09aebc8
kubectl get pod
kubectl get nod
kubectl -n kube-system
kubectl describe pod nginx-6799fc88d8-lwqb7
kubectl logs --tail=300 -f nginx-6799fc88d8-lwqb7
kubectl debug -n zstack edge-vm-controller-6bbfc84f4f-hj66v --image centos --target edge-vm-controller -it
kubectl debug cdebug-64cd86798b-sjxrl -it --image=centos --share-processes --copy-to=cdebug-debug -- sh
kubectl debug node/10.69.202.146 -it --image=centos -- shchroot /host
kubectl exec nginx-6799fc88d8-lwqb7 -it -- /bin/sh
kubectl exec mypod -c ruby-container -it -- bash
kubectl config set-context $(kubectl config current-context) --namespace=kube-ops
kubectl get pods -o yaml
kubectl get pod -A --show-labels
kubectl get pod -A --selector="k8s-app=kube-dns"
kubectl exec podName env
kubectl exec nginx-app-4028413181-cnt1i ps aux
kubectl auth can-i create pods --all-namespaces
kubect get job \ kubect get cronjob
df -Th
journalctl -l -u kube-apiserver
journalctl -l -u kube-controller-manager
journalctl -l -u kube-scheduler
journalctl -l -u kubelet
journalctl -l -u kube-proxy
-o=custom-columns=<spec> #使用逗号分隔的自定义列列表打印表格
-o=custom-columns-file=<filename> #使用文件中的自定义列模板打印表格
-o=json #输出JSON 格式的API对象
-o=jsonpath=< template> #打印jsonpath表达式中定义的字段
-o=jsonpath-file=<filename> #打印由文件中的jsonpath表达式定义的字段
-o=name #仅打印资源名称
-o=wide #以纯文本格式输出任何附加信息,对于Pod ,包含节点名称
-o=yaml #输出 YAML 格式的 API 对象
kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -n kubesphere-logging-system
2.操作类指令
kubectl create -f xxx.yaml
kubectl apply -f xxx.yaml
kubectl apply -f <directory>
kubectl create namespace test
kubectl edit pod podName
kubectl delete pod podName
kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir
kubectl cordon k8s-node1
3. 高级指令
$ kubectl rollout history daemonset <daemonset-name>
kubectl rollout history deploy php-apache
$ kubectl rollout history daemonset <daemonset-name> --revision=1
$ kubectl rollout undo daemonset <daemonset-name> --to-revision=<revi
sion>
$ kubectl rollout status deploy <daemonset-name>
kubectl scale deployment php-apache --replicas=2
kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10
kubectl set image deployment/nginx-deployment my-nginx=nginx:1.9.1
kubectl label pods my-pod new-label=awesome
kubectl annotate pods my-pod icon-url=http://goo.gl/XXBTWq
kubectl patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}'
dashboard
kubectl create serviceaccount dashboard-admin -n kube-system
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
样例
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: app-test namespace: app-test
lables:
apps: nginx
annotations:
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80