- 避免dns在同一个机器
kubectl edit deploy/coredns -n kube-system
template:
metadata:
creationTimestamp: null
labels:
k8s-app: kube-dns
spec:
affinity: # 添加start
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchExpressions:
- key: k8s-app
operator: In
values:
- kube-dns
topologyKey: kubernetes.io/hostname
weight: 100 # 添加end
containers:
- args:
- -conf
- /etc/coredns/Corefile
image: k8s.gcr.io/coredns:1.2.6
imagePullPolicy: IfNotPresent`
- k8s命令
kubeadm token create --print-join-command 生成新的集群token
kubectl expose rc kubia --type=NodePort --name kubia-http 部署service的方式
kubectl get pods -o wide 查看pods在那个节点
kubectl get nodes -o wide 查看nodes详情
kubectl describe pod kubia-lx6vz 查看pod详情
kubectl get po kubia-74vt8 -o yaml 查看已部署的pod的yaml文件
kubectl delete pods --all --grace-period=0 --force 删除所有的pods
kubectl run kubia --image=172.16.24.207:5000/kubia --port=8080 --generator=run/v1 创建服务
kubectl expose rc kubia --type=NodePort --name kubia-http 创建service --type=nodeport可以通过nodeip+serviceport访问
kubectl scale rc kubia --replicas=3 为kubia水平扩展
kubectl get replicationcontrollers 查看水平扩展情况 kubectl get rc
kubectl get deployment 查看dm信息
kubectl create -f kubia-manual.yaml 用kubia-manual.yaml创建pod
kubectl logs kubia-manual -c kubia 查看pod日志
kubectl port-forward kubia-manual 8888:8080 通过端口转发链接pod
kubectl get pods --show-labels 展示带lable的pods
kubectl label po kubia-manual creation_method=manual 给现有pod添加label
kubectl label po kubia-manual-v2 env=debug --overwrite 更改现有pod的label
kubectl get pod -l creation_method=manual 通过标签选出pod
kubectl label node node1 gpu=true 为node1添加标签 gpu=true
kubectl get nodes -l gpu=true 显示标签为gpu=true的node
kubectl get ns 查看命名空间
kubectl delete pod --all 删除当前命名空间的所有pod
kubectl get cs 获取集群状态
kubectl delete pod rtb-adapter-gdt-yz2-5120-spqrp --grace-period=0 --force 强制删除pod会减少副本数
kubectl label node nodename app=kubia
kubectl rolling-update my-replication-controller --image=nginx:1.13.7滚动升级
3.打印初始化文件和加入文件
kubeadm config print init-defaults 初始化文件
kubeadm config print join-defaults 加入集群config
4.初始化文件
apiVersion: kubeadm.k8s.io/v1beta2
kind: InitConfiguration
bootstrapTokens:
- groups:
- system:bootstrappers:kubeadm:default-node-token
token: abcdef.0123456789abcdef
ttl: 24h0m0s
usages:
- signing
- authentication
---
imageRepository: harbor.emarbox.com/yzhtest
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
kubernetesVersion: v1.19.3
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controlPlaneEndpoint: 172.16.107.15:8443
controllerManager: {}
etcd:
external:
endpoints:
- http://172.16.107.13:2379
- http://172.16.107.14:2379
- http://172.16.107.16:2379
networking:
dnsDomain: cluster.local
serviceSubnet: 10.96.0.0/12
podSubnet: 10.244.0.0/16
apiServer:
extraArgs:
v: "2"
logtostderr: "false"
log-dir: "/var/log/kubernetes"
extraVolumes:
- name: "k8s-log"
hostPath: "/var/log/kubernetes"
mountPath: "/var/log/kubernetes"
pathType: "DirectoryOrCreate"
- name: "timezone"
hostPath: "/etc/localtime"
mountPath: "/etc/localtime"
readOnly: true
pathType: "File"
timeoutForControlPlane: 4m0s
certSANs:
- emarsys107013
- emarsys107014
- emarsys107016
- "172.16.107.13"
- "172.16.107.14"
- "172.16.107.15"
- "172.16.107.16"
controllerManager:
extraArgs:
bind-address: 0.0.0.0
experimental-cluster-signing-duration: "87600h"
v: "2"
logtostderr: "false"
log-dir: "/var/log/kubernetes"
extraVolumes:
- name: "k8s-log"
hostPath: "/var/log/kubernetes"
mountPath: "/var/log/kubernetes"
pathType: "DirectoryOrCreate"
- name: "timezone"
hostPath: "/etc/localtime"
mountPath: "/etc/localtime"
readOnly: true
pathType: "File"
scheduler:
extraArgs:
address: 0.0.0.0
v: "2"
logtostderr: "false"
log-dir: "/var/log/kubernetes"
extraVolumes:
- name: "k8s-log"
hostPath: "/var/log/kubernetes"
mountPath: "/var/log/kubernetes"
pathType: "DirectoryOrCreate"
- name: "timezone"
hostPath: "/etc/localtime"
mountPath: "/etc/localtime"
readOnly: true
pathType: "File"
dns:
type: CoreDNS
---
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
failSwapOn: false
cgroupDriver: systemd
rotateCertificates: true
evictionHard:
"imagefs.available": "8%"
"memory.available": "256Mi"
"nodefs.available": "8%"
"nodefs.inodesFree": "5%"