背景
之前因为对k8s不熟悉,所以云主机上的k8s不是由我来安装的。根据朋友留下的文档和安装文件,安装配置了一遍,亲测可用。记录下安装步骤,以备不时之需。
安装环境:
操作系统:虚拟机中安装的最小centos7
硬盘:8GB
内存:1024M
网络:笔记本连接手机,手机打开热点(安装过程需要下载依赖包),虚拟主机配置网格模式。
备注:该安装中会有k8s证书过期的问题。解决方法可以查看该文档。
安装介质
安装介质安装步骤
初始化
设置主机名
hostnamectl set-hostname kubernetes.localdomain
swapoff
vi /etc/fstab
使用#注释第三行
重启系统
reboot
关掉 selinux
setenforce 0
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
关掉防火墙
systemctl stop firewalld
systemctl disable firewalld
将安装介质复制到虚拟主机上,绝对路径为:
/home/k8s
安装Docker
基于安装介质安装Docker
cd /home/k8s/rpms
yum install -y docker-engine-1.12.3-1.el7.centos.x86_64.rpm
将Docker设置为服务并启动
systemctl enable docker&&systemctl start docker
修改Docker配置
cat << EOF > /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
重启Doker,使用配置生效
systemctl restart docker
加载K8S在Docker上运行的组件镜像
cd /home/k8s/images
docker load < gcr.io***.tar
安装k8s
安装k8s组件
cd /home/k8s/rpms
yum install -y socat-1.7.3.2-2.el7.x86_64.rpm kubeadm-1.8.3-0.x86_64.rpm kubectl-1.8.3-0.x86_64.rpm kubelet-1.8.3-0.x86_64.rpm kubernetes-cni-0.5.1-1.x86_64.rpm
将kubelet设置为服务并启动
systemctl enable kubelet&&systemctl start kubelet
配置sysctl.d
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
初始化kubeadm
kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address 127.0.0.1 --kubernetes-version=v1.8.3
配置kubectl
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
配置flannel
cd /home/k8s/yaml
kubectl apply -f kube-flannel.yml
设置kubectl taint
kubectl taint node kubernetes.localdomain node-role.kubernetes.io/master:NoSchedule-
相关文件
kube-flannel.yml
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: flannel
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- ""
resources:
- nodes
verbs:
- list
- watch
- apiGroups:
- ""
resources:
- nodes/status
verbs:
- patch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: flannel
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: flannel
subjects:
- kind: ServiceAccount
name: flannel
namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: flannel
namespace: kube-system
---
kind: ConfigMap
apiVersion: v1
metadata:
name: kube-flannel-cfg
namespace: kube-system
labels:
tier: node
app: flannel
data:
cni-conf.json: |
{
"name": "cbr0",
"type": "flannel",
"delegate": {
"isDefaultGateway": true
}
}
net-conf.json: |
{
"Network": "10.244.0.0/16",
"Backend": {
"Type": "vxlan"
}
}
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: kube-flannel-ds
namespace: kube-system
labels:
tier: node
app: flannel
spec:
template:
metadata:
labels:
tier: node
app: flannel
spec:
hostNetwork: true
nodeSelector:
beta.kubernetes.io/arch: amd64
tolerations:
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
serviceAccountName: flannel
initContainers:
- name: install-cni
image: quay.io/coreos/flannel:v0.9.0-amd64
command:
- cp
args:
- -f
- /etc/kube-flannel/cni-conf.json
- /etc/cni/net.d/10-flannel.conf
volumeMounts:
- name: cni
mountPath: /etc/cni/net.d
- name: flannel-cfg
mountPath: /etc/kube-flannel/
containers:
- name: kube-flannel
image: quay.io/coreos/flannel:v0.9.0-amd64
command: [ "/opt/bin/flanneld", "--ip-masq", "--kube-subnet-mgr" ]
securityContext:
privileged: true
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
volumeMounts:
- name: run
mountPath: /run
- name: flannel-cfg
mountPath: /etc/kube-flannel/
volumes:
- name: run
hostPath:
path: /run
- name: cni
hostPath:
path: /etc/cni/net.d
- name: flannel-cfg
configMap:
name: kube-flannel-cfg
相关问题
部署Service时node-port受限问题的解决。
在kubernates安装的目录下,一般为/etc/kubernates/找到manifests目录下的kube-apiserver.yaml文件。
在命令行参数上添加一行配置,重启即可。
- command:
- kube-apiserver
#......中间参数太多,忽略
- --etcd-servers=http://127.0.0.1:2379
- --service-node-port-range=80-32767#添加该行参数
image: gcr.io/google_containers/kube-apiserver-amd64:v1.8.3
网友评论