博主介绍:
– 我是了 凡 微信公众号【了凡银河系】期待你的关注。未来大家一起加油啊~
下面记录kubernets 1.24 安装记录。主要使用calico作为网络插件、kong ingress作为路由转发、nginx作为四层代理。
如果安装过程中遇到问题,及时沟通,如果不能及时回应,可以关注【了凡银河系】微信公众号加微信沟通。
vi /etc/hosts
地址 master
地址 node1
hostnamectl set-hostname master
hostnamectl set-hostname node1
calico 179
k8s api 6443
node给master 的pod 访问端口 10250
2379 / 4789
# 查看交换分区的状态
sudo free -m
# 临时关闭
sudo swapoff -a
# 永久关闭: 把 /etc/fstab 中的swap注释掉
sudo sed -i 's/.*swap.*/#&/' /etc/fstab
# 临时关闭
setenforce 0
# 永久关闭
sudo sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
# 或编辑文件 /etc/selinux/config :
SELINUX=disabled
systemctl stop firewalld
systemctl disable firewalld
由于开启内核 ipv4 转发需要加载 br_netfilter 模块,所以加载下该模块
modprobe br_netfilter
编辑文件 /etc/sysctl.d/k8s.conf
vi /etc/sysctl.d/k8s.conf
在文件中添加以下内容:
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
`执行命令
sysctl -p /etc/sysctl.d/k8s.conf``
使用阿里云
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装docker
yum install docker-ce docker-ce-cli containerd.io
设置加速器并修改docker驱动
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://ovj8fg0z.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
重启并设置自启动
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
我们已经了解过容器运行时 containerd 的一些基本使用,接下来在各个节点上安装 Containerd。
由于 containerd 需要调用 runc,所以我们也需要先安装 runc,不过 containerd 提供了一个包含相关依赖的压缩包 cri-containerd-cni-${VERSION}.${OS}-${ARCH}.tar.gz,可以直接使用这个包来进行安装。
此处我们使用1.5.5 版本
下载压缩包
#下载压缩包
wget https://github.com/containerd/containerd/releases/download/v1.5.5/cri-containerd-cni-1.5.5-linux-amd64.tar.gz
#直接将压缩包解压到系统的各个目录中
tar -C / -xzf cri-containerd-cni-1.5.5-linux-amd64.tar.gz
#然后要将 /usr/local/bin 和 /usr/local/sbin 追加到 ~/.bashrc 文件的 PATH 环境变量中
export PATH=$PATH:/usr/local/bin:/usr/local/sbin
#然后执行下面的命令使其立即生效
source ~/.bashrc
kubeadm init \
--apiserver-advertise-address=主节点地址 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.24.2 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16 \
--ignore-preflight-errors=all \
| tee kubeadm-init.log
kubernetes join xxx
wget -k https://docs.projectcalico.org/manifests/calico.yaml
kubectl apply -f calico.yaml
kubectl get po -n kube-system
验证是否成功,一般会因为网络模式导致某个节点未就绪、或者使用某某云的端口未开放出现问题,可以参考下面的解决办法。
部署后,修改cm kube proxy 里的mode 为ipvs ,如果使用某某云需要将179端口开放。
- name: IP_AUTODETECTION_METHOD
value: "interface=eth0"
wget https://raw.githubusercontent.com/Kong/kubernetes-ingress-controller/master/deploy/single/all-in-one-dbless.yaml
kubectl apply -f all-in-one-dbless.yaml
kubectl get po -n kong
验证是否成功
这里主要是nginx配置四层转发,kong ingress用于七层路由转发。
mkdir /home/work
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
tar zxvf pcre-8.35.tar.gz && cd pcre-8.35
./configure --prefix=/home/work/pcre
make && make install
pcre-config --version
yum install nginx -y 当前默认版本为1.20.1
nginx -V查看当前nginx配置模块
systemctl start nginx.service -------------- 启动
systemctl stop nginx.service -------------- 停止
systemctl restart nginx.service -------------- 重启
systemctl reload nginx.service -------------- 重新加载配置
systemctl enable nginx.service -------------- 设置开机自启动
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -zxvf nginx-1.20.1.tar.gz && cd nginx-1.20.1
mv /usr/sbin/nginx /usr/sbin/nginx.bak
cp -r /etc/nginx /etc/nginx.bak
yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmakepcre-develnanowget gcc gcc-c++ ncurses-devel per redhat-rpm-config.noarch
./configure --with-stream --prefix=/home/work/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/home/work/pcre-8.35
make && make install
/home/work/nginx/sbin/nginx
/home/work/nginx/sbin/nginx -s reload
stream {
server {
listen 80;
proxy_connect_timeout 60s;
proxy_timeout 1800s;
proxy_next_upstream on;
proxy_next_upstream_tries 3;
proxy_next_upstream_timeout 10s;
proxy_pass tcp_80;
}
upstream tcp_80 {
hash $remote_addr consistent;
server node1:30080 max_fails=3 fail_timeout=15s;
# check interval=3000 rise=2 fall=5 timeout=1000 type=tcp;
}
server {
listen 443;
proxy_connect_timeout 60s;
proxy_timeout 1800s;
proxy_next_upstream on;
proxy_next_upstream_tries 3;
proxy_next_upstream_timeout 10s;
proxy_pass tcp_443;
}
upstream tcp_443{
hash $remote_addr consistent;
server node1:30443 max_fails=3 fail_timeout=15s;
# check interval=3000 rise=2 fall=5 timeout=1000 type=tcp;
}
}
#user nobody;
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
}
include stream.conf;
vim nginx-test.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: preview
spec:
replicas: 3
selector:
matchLabels:
app: nginx-pod
template:
metadata:
labels:
app: nginx-pod
spec:
containers:
- name: nginx
image: nginx:1.17.1
ports:
- containerPort: 80
kind: Service
metadata:
name: nginx-service
namespace: preview
spec:
selector:
app: nginx-pod
type: ClusterIP
ports:
- port: 80
targetPort: 80
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-nginx
namespace: preview
annotations:
konghq.com/strip-path: "true"
kubernetes.io/ingress.class: kong
spec:
rules:
- host: "可解析并访问的域名地址"
http:
paths:
- pathType: Prefix
path: /api
backend:
service:
name: nginx-service
port:
number: 80
kubectl apply -f nginx-test.yaml
kubectl get po -n preview
kubectl get svc -n preview
kubectl get ing -n preview
curl 域名地址/api
创作不易,点个赞吧!
如果需要后续再看点个收藏!
如果对我的文章有兴趣给个关注!
如果有问题,可以关注公众号【了凡银河系】点击联系我私聊。