1、环境准备
我这里的配置是一个master一个node节点
节点 | 服务器IP |
---|---|
master | 10.10.100.131 |
node | 10.10.100.139 |
2、安装配置
2.1 Master节点
服务端安装
yum -y install etcd kubernetes-master
服务端的配置文件在 /etc/kubernetes 里面,如下几个文件
# ls -lh /etc/kubernetes/
apiserver config controller-manager scheduler
apiserver文件配置
###
# kubernetes system config
#
# The following values are used to configure the kube-apiserver
#
# The address on the local server to listen to.
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
# The port on the local server to listen on.
KUBE_API_PORT="--port=8080"
# Port minions listen on
KUBELET_PORT="--kubelet-port=10250"
# Comma separated list of nodes in the etcd cluster
KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379"
# Address range to use for services
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"
# default admission control policies
# KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"
# Add your own!
KUBE_API_ARGS=""
config文件配置
# logging to stderr means we get it in the systemd journal
KUBE_LOGTOSTDERR="--logtostderr=true"
# journal message level, 0 is debug
KUBE_LOG_LEVEL="--v=0"
# Should this cluster be allowed to run privileged docker containers
KUBE_ALLOW_PRIV="--allow-privileged=false"
# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://127.0.0.1:8080"
启动服务和设置开机自启动
for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do systemctl restart $SERVICES;systemctl enable $SERVICES;systemctl status $SERVICES ; done
2.2 Node节点
软件安装
yum -y install flannel kubernetes-node
Node节点的配置主要有两个地方,一个在/etc/sysconfig/flanneld,另一个在/etc/kubernetes目录下
# ls /etc/kubernetes/
config kubelet proxy
flanneld配置
# Flanneld configuration options
# etcd url location. Point this to the server where etcd runs
FLANNEL_ETCD_ENDPOINTS="http://10.10.100.131:2379"
# etcd config key. This is the configuration key that flannel queries
# For address range assignment
FLANNEL_ETCD_PREFIX="/atomic.io/network"
# Any additional options that you want to pass
#FLANNEL_OPTIONS=""
config文件配置
# logging to stderr means we get it in the systemd journal
KUBE_LOGTOSTDERR="--logtostderr=true"
# journal message level, 0 is debug
KUBE_LOG_LEVEL="--v=0"
# Should this cluster be allowed to run privileged docker containers
KUBE_ALLOW_PRIV="--allow-privileged=false"
# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://10.10.100.131:8080"
kubelet文件配置
# The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)
KUBELET_ADDRESS="--address=0.0.0.0"
# The port for the info server to serve on
KUBELET_PORT="--port=10250"
# You may leave this blank to use the actual hostname
KUBELET_HOSTNAME="--hostname-override=10.10.100.139"
# location of the api-server
KUBELET_API_SERVER="--api-servers=http://10.10.100.131:8080"
# pod infrastructure container
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
# Add your own!
KUBELET_ARGS="--logtostderr=false --v=0 --log-dir=/data/logs/kubernetes"
配置完成后,启动服务,并配置开机自启动
for SERVICES in kube-proxy kubelet docker flanneld;do systemctl restart $SERVICES;systemctl enable $SERVICES;systemctl status $SERVICES; done
3、Master管理
可以看到node节点的状态和运行时间
# kubectl get node
NAME STATUS AGE
10.10.100.139 Ready 21h
3.1 创建Pod
新建nginx-pod.yml文件,内容如下:
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
hostPort: 80
创建pod
kubectl create -f nginx-pod.yaml
创建完成后,运行命令查看pod的状态
# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-pod 1/1 Running 0 20h
在node节点上运行 docker ps 就能够看到新建的容器了