k8s安装
2021-11-02 17:10:08 90 举报
AI智能生成
Kubernetes(简称k8s)是一个开源的容器编排平台,用于自动化应用程序部署、扩展和管理。安装k8s需要先安装Docker,然后使用kubeadm工具进行初始化配置。在一台主机上运行kubeadm init命令,它会下载并安装Kubernetes组件,包括etcd、kubelet和kubectl等。初始化完成后,可以使用kubectl命令行工具管理集群。接下来,可以根据需求部署应用程序到Kubernetes集群中。k8s提供了丰富的功能,如自动扩缩容、服务发现、负载均衡等,可以帮助开发者更高效地管理和运维应用程序。
作者其他创作
大纲/内容
Centos安装NFS
# 服务端
yum install nfs-utils
systemctl enable rpcbind
systemctl enable nfs
systemctl start rpcbind
systemctl start nfs
mkdir /k8s
chmod 755 /k8s
echo '/k8s/ *(rw,sync,no_root_squash,no_all_squash)' >> /etc/exports
systemctl restart nfs
# 客户端
yum install nfs-utils
systemctl enable rpcbind
systemctl start rpcbind
mkdir /k8s
mount -t nfs 192.168.33.10:/k8s /k8s
yum install nfs-utils
systemctl enable rpcbind
systemctl enable nfs
systemctl start rpcbind
systemctl start nfs
mkdir /k8s
chmod 755 /k8s
echo '/k8s/ *(rw,sync,no_root_squash,no_all_squash)' >> /etc/exports
systemctl restart nfs
# 客户端
yum install nfs-utils
systemctl enable rpcbind
systemctl start rpcbind
mkdir /k8s
mount -t nfs 192.168.33.10:/k8s /k8s
常用命令
查看内核版本信息
cat /proc/version
uname -a
apt源
/etc/apt/sources.list
更新软件列表
apt-get update
更新软件
apt-get upgrade
docker镜像加速
{
"registry-mirrors": [
"http://mirror.ccs.tencentyun.com",
"http://f0fchtxz.mirror.aliyuncs.com",
"http://docker.mirrors.ustc.edu.cn"
]
}
"registry-mirrors": [
"http://mirror.ccs.tencentyun.com",
"http://f0fchtxz.mirror.aliyuncs.com",
"http://docker.mirrors.ustc.edu.cn"
]
}
/etc/docker/daemon.json
k8s源
apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
apt update
Ubuntu安装k8s单节点
apt remove -y kubelet kubeadm kubectl
apt install -y kubelet=1.21.0-00 kubeadm=1.21.0-00 kubectl=1.21.0-00
kubeadm init --image-repository=ccr.ccs.tencentyun.com/comeonjy --pod-network-cidr=10.244.0.0/16 --kubernetes-version=v1.21.0
docker pull registry.aliyuncs.com/google_containers/coredns:1.8.0
docker tag registry.aliyuncs.com/google_containers/coredns:1.8.0 ccr.ccs.tencentyun.com/comeonjy/coredns/coredns:v1.8.0
docker push ccr.ccs.tencentyun.com/comeonjy/coredns:v1.8.0
# docker pull ccr.ccs.tencentyun.com/comeonjy/coredns:v1.8.0
# docker tag ccr.ccs.tencentyun.com/comeonjy/coredns:v1.8.0 ccr.ccs.tencentyun.com/comeonjy/coredns/coredns:v1.8.0
docker pull registry.aliyuncs.com/google_containers/kube-apiserver:v1.21.5
docker tag registry.aliyuncs.com/google_containers/kube-apiserver:v1.21.5 ccr.ccs.tencentyun.com/comeonjy/kube-apiserver:v1.21.5
docker push ccr.ccs.tencentyun.com/comeonjy/kube-apiserver:v1.21.5
docker pull registry.aliyuncs.com/google_containers/kube-controller-manager-amd64:v1.21.5
docker tag registry.aliyuncs.com/google_containers/kube-controller-manager-amd64:v1.21.5 ccr.ccs.tencentyun.com/comeonjy/kube-controller-manager:v1.21.5
docker push ccr.ccs.tencentyun.com/comeonjy/kube-controller-manager:v1.21.5
docker pull registry.aliyuncs.com/google_containers/kube-scheduler:v1.21.5
docker tag registry.aliyuncs.com/google_containers/kube-scheduler:v1.21.5 ccr.ccs.tencentyun.com/comeonjy/kube-scheduler:v1.21.5
docker push ccr.ccs.tencentyun.com/comeonjy/kube-scheduler:v1.21.5
docker pull registry.aliyuncs.com/google_containers/kube-proxy:v1.21.5
docker tag registry.aliyuncs.com/google_containers/kube-proxy:v1.21.5 ccr.ccs.tencentyun.com/comeonjy/kube-proxy:v1.21.5
docker push ccr.ccs.tencentyun.com/comeonjy/kube-proxy:v1.21.5
docker pull registry.aliyuncs.com/google_containers/pause:3.4.1
docker tag registry.aliyuncs.com/google_containers/pause:3.4.1 ccr.ccs.tencentyun.com/comeonjy/pause:3.4.1
docker push ccr.ccs.tencentyun.com/comeonjy/pause:3.4.1
docker pull registry.aliyuncs.com/google_containers/etcd:3.4.13-0
docker tag registry.aliyuncs.com/google_containers/etcd:3.4.13-0 ccr.ccs.tencentyun.com/comeonjy/etcd:3.4.13-0
docker push ccr.ccs.tencentyun.com/comeonjy/etcd:3.4.13-0
apt install -y kubelet=1.21.0-00 kubeadm=1.21.0-00 kubectl=1.21.0-00
kubeadm init --image-repository=ccr.ccs.tencentyun.com/comeonjy --pod-network-cidr=10.244.0.0/16 --kubernetes-version=v1.21.0
docker pull registry.aliyuncs.com/google_containers/coredns:1.8.0
docker tag registry.aliyuncs.com/google_containers/coredns:1.8.0 ccr.ccs.tencentyun.com/comeonjy/coredns/coredns:v1.8.0
docker push ccr.ccs.tencentyun.com/comeonjy/coredns:v1.8.0
# docker pull ccr.ccs.tencentyun.com/comeonjy/coredns:v1.8.0
# docker tag ccr.ccs.tencentyun.com/comeonjy/coredns:v1.8.0 ccr.ccs.tencentyun.com/comeonjy/coredns/coredns:v1.8.0
docker pull registry.aliyuncs.com/google_containers/kube-apiserver:v1.21.5
docker tag registry.aliyuncs.com/google_containers/kube-apiserver:v1.21.5 ccr.ccs.tencentyun.com/comeonjy/kube-apiserver:v1.21.5
docker push ccr.ccs.tencentyun.com/comeonjy/kube-apiserver:v1.21.5
docker pull registry.aliyuncs.com/google_containers/kube-controller-manager-amd64:v1.21.5
docker tag registry.aliyuncs.com/google_containers/kube-controller-manager-amd64:v1.21.5 ccr.ccs.tencentyun.com/comeonjy/kube-controller-manager:v1.21.5
docker push ccr.ccs.tencentyun.com/comeonjy/kube-controller-manager:v1.21.5
docker pull registry.aliyuncs.com/google_containers/kube-scheduler:v1.21.5
docker tag registry.aliyuncs.com/google_containers/kube-scheduler:v1.21.5 ccr.ccs.tencentyun.com/comeonjy/kube-scheduler:v1.21.5
docker push ccr.ccs.tencentyun.com/comeonjy/kube-scheduler:v1.21.5
docker pull registry.aliyuncs.com/google_containers/kube-proxy:v1.21.5
docker tag registry.aliyuncs.com/google_containers/kube-proxy:v1.21.5 ccr.ccs.tencentyun.com/comeonjy/kube-proxy:v1.21.5
docker push ccr.ccs.tencentyun.com/comeonjy/kube-proxy:v1.21.5
docker pull registry.aliyuncs.com/google_containers/pause:3.4.1
docker tag registry.aliyuncs.com/google_containers/pause:3.4.1 ccr.ccs.tencentyun.com/comeonjy/pause:3.4.1
docker push ccr.ccs.tencentyun.com/comeonjy/pause:3.4.1
docker pull registry.aliyuncs.com/google_containers/etcd:3.4.13-0
docker tag registry.aliyuncs.com/google_containers/etcd:3.4.13-0 ccr.ccs.tencentyun.com/comeonjy/etcd:3.4.13-0
docker push ccr.ccs.tencentyun.com/comeonjy/etcd:3.4.13-0
# 安装flannel
https://github.com/flannel-io/flannel/edit/master/Documentation/kube-flannel.yml
# 让master能被调度pod
kubectl taint nodes --all node-role.kubernetes.io/master-
# 安装dashboard
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.2.0/aio/deploy/recommended.yaml
https://github.com/flannel-io/flannel/edit/master/Documentation/kube-flannel.yml
# 让master能被调度pod
kubectl taint nodes --all node-role.kubernetes.io/master-
# 安装dashboard
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.2.0/aio/deploy/recommended.yaml
https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/creating-sample-user.md
Centos安装k8s集群
kubeadm
# master
kubeadm init --image-repository=ccr.ccs.tencentyun.com/comeonjy --apiserver-advertise-address=192.168.33.10 --kubernetes-version v1.21.0 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://github.com/flannel-io/flannel/edit/master/Documentation/kube-flannel.yml
#node
kubeadm join 192.168.33.10:6443 --token lku3ru.92hxr6rgkild9y6q --discovery-token-ca-cert-hash sha256:167d44a0139de4a0e79aaa98b860c7a423aa0262e375c65d92ee27594a768d84
yum update -y
yum install -y vim yum-utils device-mapper-persistent-data lvm2
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://f0fchtxz.mirror.aliyuncs.com","https://mirror.ccs.tencentyun.com
"],
"exec-opts":["native.cgroupdriver=systemd"]
}
EOF
systemctl daemon-reload
systemctl restart docker
systemctl start docker && systemctl enable docker
setenforce 0
sed -i 's/SELINUX=enforcing/\SELINUX=permissive/' /etc/selinux/config
swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
sed -i -e '$a net.bridge.bridge-nf-call-iptables = 1' /etc/sysctl.conf
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
tee /etc/yum.repos.d/kubernetes.repo <<-'EOF'
[kubernetes]
name=Kubernetes Repository
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
EOF
yum install -y kubelet-1.21.0-0 kubeadm-1.21.0-0 kubectl-1.21.0-0
systemctl enable kubelet && systemctl start kubelet
docker pull ccr.ccs.tencentyun.com/comeonjy/coredns:v1.8.0
docker tag ccr.ccs.tencentyun.com/comeonjy/coredns:v1.8.0 ccr.ccs.tencentyun.com/comeonjy/coredns/coredns:v1.8.0
docker rmi ccr.ccs.tencentyun.com/comeonjy/coredns
docker pull ccr.ccs.tencentyun.com/comeonjy/kube-apiserver:v1.21.5
docker pull ccr.ccs.tencentyun.com/comeonjy/kube-controller-manager:v1.21.5
docker pull ccr.ccs.tencentyun.com/comeonjy/kube-scheduler:v1.21.5
docker pull ccr.ccs.tencentyun.com/comeonjy/kube-proxy:v1.21.5
docker pull ccr.ccs.tencentyun.com/comeonjy/pause:3.4.1
docker pull ccr.ccs.tencentyun.com/comeonjy/etcd:3.4.13-0
yum install -y vim yum-utils device-mapper-persistent-data lvm2
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://f0fchtxz.mirror.aliyuncs.com","https://mirror.ccs.tencentyun.com
"],
"exec-opts":["native.cgroupdriver=systemd"]
}
EOF
systemctl daemon-reload
systemctl restart docker
systemctl start docker && systemctl enable docker
setenforce 0
sed -i 's/SELINUX=enforcing/\SELINUX=permissive/' /etc/selinux/config
swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
sed -i -e '$a net.bridge.bridge-nf-call-iptables = 1' /etc/sysctl.conf
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
tee /etc/yum.repos.d/kubernetes.repo <<-'EOF'
[kubernetes]
name=Kubernetes Repository
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
EOF
yum install -y kubelet-1.21.0-0 kubeadm-1.21.0-0 kubectl-1.21.0-0
systemctl enable kubelet && systemctl start kubelet
docker pull ccr.ccs.tencentyun.com/comeonjy/coredns:v1.8.0
docker tag ccr.ccs.tencentyun.com/comeonjy/coredns:v1.8.0 ccr.ccs.tencentyun.com/comeonjy/coredns/coredns:v1.8.0
docker rmi ccr.ccs.tencentyun.com/comeonjy/coredns
docker pull ccr.ccs.tencentyun.com/comeonjy/kube-apiserver:v1.21.5
docker pull ccr.ccs.tencentyun.com/comeonjy/kube-controller-manager:v1.21.5
docker pull ccr.ccs.tencentyun.com/comeonjy/kube-scheduler:v1.21.5
docker pull ccr.ccs.tencentyun.com/comeonjy/kube-proxy:v1.21.5
docker pull ccr.ccs.tencentyun.com/comeonjy/pause:3.4.1
docker pull ccr.ccs.tencentyun.com/comeonjy/etcd:3.4.13-0
# master
kubeadm init --image-repository=ccr.ccs.tencentyun.com/comeonjy --apiserver-advertise-address=192.168.33.10 --kubernetes-version v1.21.0 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://github.com/flannel-io/flannel/edit/master/Documentation/kube-flannel.yml
#node
kubeadm join 192.168.33.10:6443 --token lku3ru.92hxr6rgkild9y6q --discovery-token-ca-cert-hash sha256:167d44a0139de4a0e79aaa98b860c7a423aa0262e375c65d92ee27594a768d84
## 修改为各自IP
tee /etc/sysconfig/kubelet <<-'EOF'
KUBELET_EXTRA_ARGS="--node-ip=192.168.33.10"
EOF
systemctl restart kubelet
tee /etc/sysconfig/kubelet <<-'EOF'
KUBELET_EXTRA_ARGS="--node-ip=192.168.33.10"
EOF
systemctl restart kubelet
0 条评论
下一页
为你推荐
查看更多