在 Kubernetes 上使用 NodePort 暴露的服务,只有在 pod 所调度的那个 node 节点 ip 能够访问,集群其他节点不能访问,这一般是由于节点的 iptables 链规则导致的。
iptables -S -t filter
iptables -P FORWARD ACCEPT
curl 定时访问某个链接
while true; do curl xxx ;sleep 1 ;done;
curl -s -I -HHost:httpbin.example.com “http:// I N G R E S S H O S T : INGRESS_HOST: INGRESSHOST:INGRESS_PORT/status/200”
consul 常见命令
consul 一键导出命令 export
consul kv export --http-addr=http://10.20.1.176:8500 -token=p2BE1AtpwPbrxZdC6k+eXA== ‘’ > consul_kv.json
consul kv import --http-addr=http://10.12.142.216:8500 -token=b3a9bca3-6e8e-9678-ea35-ccb8fb272d42 @consul_kv_xxx.json
一键导出 k8s 或者 calico 的镜像
docker save $(docker images | grep “registry.aliyuncs.com” | awk ‘BEGIN{OFS=":";ORS=" "}{print $1,$2}’) -o k8s-1.17.2-images.tar
docker save $(docker images | grep “calico” | awk ‘BEGIN{OFS=":";ORS=" "}{print $1,$2}’) -o calico-3.12-images.tar
Kubernetes 删除清理 Evicted Pod
kubectl get pods -A | grep Evicted | awk ‘{print $2 " --namespace=" $1}’ | xargs kubectl delete pod
Kubernetes 使用 kubelet 升级 deployment
#Set a deployment’s nginx container image to ‘nginx:1.9.1’, and its busybox container image to ‘busybox’.
kubectl set image deployment/nginx busybox=busybox nginx=nginx:1.9.1
Kubernetes 强制删除某个 Pod
kubectl delete pod Pod名称 -n ns命令空间 --grace-period=0 --force
使用阿里云镜像地址安装 k8s 集群
kubeadm init --kubernetes-version=1.17.2 --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr=192.168.0.0/16
注意上述 pod cidr 地址范围配置
安装 k8s 1.14.8 kubelet 报错
yum install -y kubeadm-1.14.8-0 kubelet-1.14.8-0 kubectl-1.14.8-0 --disableexcludes=kubernetes 安装时报错
yum install kubelet-1.14.8-0 -y && yum install kubectl-1.14.8-0 -y && yum install kubeadm-1.14.8-0 -y
卸载移除 kubeadm、kubectl、kubelet
yum remove kubeadm.x86_64 kubectl.x86_64 kubelet.x86_64 -y
Centos 7 安装 docker
sudo yum install -y yum-utils
device-mapper-persistent-data
lvm2
sudo yum-config-manager
–add-repo
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
centos 7.0 系统更改镜像源
// 备份本地 yum 源
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
// 获取阿里 yum 源配置
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
// 或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
// 更新catch
// 清除系统所有的yum缓存 yum makecache
// 生成yum缓存
yum clean all
docker 设置镜像仓库代理
{
“registry-mirrors”: [
“https://docker.mirrors.ustc.edu.cn”,
“http://hub-mirror.c.163.com”
],
“insecure-registries”:[“xxx.cn:5000”],
“max-concurrent-downloads”: 10,
“log-driver”: “json-file”,
“log-level”: “warn”,
“log-opts”: {
“max-size”: “10m”,
“max-file”: “3”
},
“data-root”: “/var/lib/docker”
}
编辑 /etc/docker/daemon.json 文件
systemctl daemon-reload
systemctl restart docker
docker 启动 consul 以及相关配置信息
docker pull consul:1.7.2
docker run -d --name consul_server1 --net=host consul:1.7.2 agent -server -bind=10.20.1.104 -bootstrap-expect=1 -client 0.0.0.0 -ui
docker exec -t consul_server1 consul members
docker exec -t consul_server1 consul info | grep leader
使用 postman 往 consul 中注册服务
http://10.20.1.104:8500/v1/agent/service/register
{
“ID”: “test-istio-httpbin”,
“Name”: “test-istio-httpbin”,
“Tags”: [
“test=istio”
],
“Address”: “10.20.1.104”,
“Port”: 9000,
“Check”: {
“TCP”: “10.20.1.104:9000”,
“interval”: “30s”
}
}
使用 postman 注销 consul 中的服务
http://10.20.1.104:8500/v1/agent/service/deregister/test-istio-httpbin
docker 相关问题
清理退出相关异常进程 :docker rm $(docker ps -a -q)
清理 none 镜像: docker rmi $(docker images | grep “^” | awk “{print $3}”)