文章目录
k8s踩坑日记
vmware克隆时ip重复问题
Ubuntu从17.10开始,已放弃在/etc/network/interfaces里配置IP地址,即使配置也不会生效,而是改成netplan方式,配置写在/etc/netplan/01-netcfg.yaml或者类似名称的yaml文件里。
network:
ethernets:
ens33: # 配置的网卡名称
dhcp4: no # 关闭dhcp4
dhcp6: no # 关闭dhcp6
addresses: [192.168.0.120/24] # 设置本机IP地址及掩码
gateway4: 192.168.0.1 # 设置网关
nameservers:
addresses: [114.114.114.114, 8.8.8.8] # 设置DNS
version: 2
更改完后执行netplan apply
kubeadm init时丢失"kubeadm join"命令,如何找回?
kubeadm token create --print-join-command
k8s启动日志查看
journalctl -f -u kubelet
ssh连接出现Network error:Software caused connection abort问题
- 编辑服务器端 vi /etc/ssh/sshd_config
- 修改参数:ClientAliveInterval 0,改为60或更大
- 重启:service sshd restart
k8s获取版本信息
- 使用kubectl version(client :kubectl版本,server:master节点的k8s版本信息)
- 使用kubectl get nodes获取集群可用节点,也可获取安装k8s的版本信息
删除pod
kubectl delete pod [podName]
提示:–replicas has been deprecated, has no effect and will be removed in the future.
执行kubectl run nginx --image=nginx --replicas=2 --port=80时提示:
F l a g − − r e p l i c a s h a s b e e n d e p r e c a t e d , h a s n o e f f e c t a n d w i l l b e r e m o v e d i n t h e f u t u r e \color{#FF3030}{Flag --replicas has been deprecated, has no effect and will be removed in the future} Flag−−replicashasbeendeprecated,hasnoeffectandwillberemovedinthefuture.
且只创建一个nginx容器实例
在K8S v1.18.0以后,–replicas已弃用 ,推荐用 deployment 创建 pods
vim nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
# 创建2个nginx容器
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
创建:kubectl apply -f nginx-deployment.yaml
查看 Pods :kubectl get pods / kubectl get deployment,
下面是我已经部署好的 nginx 容器实例
get pods
get deployment
暴露服务:kubectl expose deployment nginx-deployment --port=80 --type=LoadBalancer
查看服务状态(查看对外的端口):kubectl get services
ubuntu apt-get 指定版本
sudo apt-get install softname=version
eg: sudo apt-get install openssh-client=1:6.6p1-2ubuntu1
ubuntu 列出一个软件的版本
sudo apt-cache madison soft_name
eg: sudo apt-cache madison openssh-client
docker安装
sudo apt-get -y install docker-ce=5:18.09.6~3-0~ubuntu-bionic docker-ce-cli=5:18.09.6~3-0~ubuntu-bionic
apt-get install -y kubelet=1.14.1-00 kubeadm=1.14.1-00 kubectl=1.14.1-00
sudo apt-get install kubernetes-cni=0.7.5-00
查看所有pod
kubectl get pods --all-namespaces -o wide //-o wide事显示所有node
kubectl describe pod calico-kube-controllers-f6ff9cbbb-ghwq5 -n kube-system
问题:Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
dig @114.114.114.114 registry-1.docker.io
vim /etc/hosts并添加ip:52.4.20.24 registry-1.docker.io
K8s无法删除 PV
系统内有一个已经不再使用的 PV ,已经删除了与其关联的 Pod 及 PVC ,并对其执行了删除命令,但是无法正常删除
解决方法
$ kubectl patch pv pv-nfs-gysl -p ‘{“metadata”:{“finalizers”:null}}’