centos7.5单机yum安装kubernetes
1.系统配置
centos7.5
docker 1.13.1 centos7下安装docker
2.关闭防火墙,selinux,swapoff
systemctl disable firewalld #停止firewall
systemctl stop firewalld #禁止firewall开机启动
firewall-cmd --state #查看防火墙状态
swapoff -a
# 临时关闭
$ setenforce 0
# 永久关闭
$ vim /etc/selinux/config
SELINUX=disabled
3.yum安装k8s
[root@localhost yum.repos.d]# pwd
/etc/yum.repos.d
[root@localhost yum.repos.d]# cat kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=
gpgcheck=
repo_gpgcheck=
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]#yum remove etcd kubernetes [root@localhost yum.repos.d]# yum install -y etcd kubernetes
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.cqu.edu.cn
* extras: mirrors.nwsuaf.edu.cn
* updates: mirrors.cqu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package etcd.x86_64 :3.3.-.el7.centos will be installed
---> Package kubernetes.x86_64 :1.5.-0.7.git269f928.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================
Installing:
etcd x86_64 3.3.-.el7.centos extras M
kubernetes x86_64 1.5.-0.7.git269f928.el7 extras k Transaction Summary
============================================================================================================================================================================
Install Packages Total download size: M
Installed size: M
Downloading packages:
(/): kubernetes-1.5.-0.7.git269f928.el7.x86_64.rpm | kB ::
(/): etcd-3.3.-.el7.centos.x86_64.rpm | MB ::
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 1.6 MB/s | MB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : kubernetes-1.5.-0.7.git269f928.el7.x86_64 /
Installing : etcd-3.3.-.el7.centos.x86_64 /
Verifying : etcd-3.3.-.el7.centos.x86_64 /
Verifying : kubernetes-1.5.-0.7.git269f928.el7.x86_64 / Installed:
etcd.x86_64 :3.3.-.el7.centos kubernetes.x86_64 :1.5.-0.7.git269f928.el7 Complete!
修改配置
/etc/sysconfig/docker 修改OPTIONS='--selinux-enabled=false --insecure-registry gcr.io'并重启docker
/etc/kubernetes/apiserver KUBE_ADMISSION_CONTROL项删除ServiceAccount
[root@localhost yum.repos.d]# vi /etc/sysconfig/docker # /etc/sysconfig/docker # Modify these options if you want to change the way the docker daemon runs
##OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false'
OPTIONS='--selinux-enabled=false --insecure-registry gcr.io'
if [ -z "${DOCKER_CERT_PATH}" ]; then
DOCKER_CERT_PATH=/etc/docker
fi # Do not add registries in this file anymore. Use /etc/containers/registries.conf
# instead. For more information reference the registries.conf() man page. # Location used for temporary files, such as those created by
# docker load and build operations. Default is /var/lib/docker/tmp
# Can be overriden by setting the following environment variable.
# DOCKER_TMPDIR=/var/tmp # Controls the /etc/cron.daily/docker-logrotate cron job status.
# To disable, uncomment the line below.
# LOGROTATE=false # docker-latest daemon can be used by starting the docker-latest unitfile.
# To use docker-latest client, uncomment below lines
Entering Ex mode. Type "visual" to go to Normal mode.
:wq
"/etc/sysconfig/docker" 27L, 1157C written
[root@localhost yum.repos.d]# service docker restart
Redirecting to /bin/systemctl restart docker.service
[root@localhost yum.repos.d]# vi /etc/kubernetes/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=127.0.0.1" # 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" Entering Ex mode. Type "visual" to go to Normal mode.
:wq
"/etc/kubernetes/apiserver" 27L, 894C written
4.启动服务
启动服务:systemctl start serviceName 或者 service serviceName start
查看状态:systemctl status serviceName 或者 service serviceName status
systemctl start etcd
systemctl start docker
systemctl start kube-apiserver
systemctl start kube-controller-manager
systemctl start kube-scheduler
systemctl start kubelet
systemctl start kube-proxy
验证
[root@localhost .kube]# kubectl version
Client Version: version.Info{Major:"", Minor:"", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-05-21T09:17:39Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"", Minor:"", GitVersion:"v1.5.2", GitCommit:"269f928217957e7126dc87e6adfa82242bfe5b1e", GitTreeState:"clean", BuildDate:"2017-07-03T15:31:10Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
[root@localhost .kube]# kubectl get componentstatus
NAME STATUS MESSAGE ERROR
etcd- Healthy {"health":"true"}
scheduler Healthy ok
controller-manager Healthy ok
[root@localhost .kube]# ps -ef|grep kube
root : pts/ :: kubectl proxy --port=
kube : ? :: /usr/bin/kube-apiserver --logtostderr=true --v= --etcd-servers=http://127.0.0.1:2379 --insecure-bind-address=127.0.0.1 --allow-privileged=false --service-cluster-ip-range=10.254.0.0/16 --admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota
kube : ? :: /usr/bin/kube-controller-manager --logtostderr=true --v= --master=http://127.0.0.1:8080
kube : ? :: /usr/bin/kube-scheduler --logtostderr=true --v= --master=http://127.0.0.1:8080
root : ? :: /usr/bin/kube-proxy --logtostderr=true --v= --master=http://127.0.0.1:8080
root 38641 1 2 10:26 ? 00:01:10 /usr/bin/kubelet --logtostderr=true --v=0 --api-servers=http://127.0.0.1:8080 --address=127.0.0.1 --hostname-override=127.0.0.1 --allow-privileged=false --pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest
root : pts/ :: grep --color=auto kube
[root@localhost shell]# kubectl cluster-info
Kubernetes master is running at http://localhost:8080
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
[root@localhost software]# kubectl get nodes
NAME STATUS AGE
127.0.0.1 Ready 1h
[root@localhost software]#
5.入门实验
先拉取纯净centos镜像 docker pull centos慢问题的解决方案
dockerfile制作自己的镜像 docker利用Dockerfile来制作镜像
部署自己的镜像
[root@localhost software]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
base_tomcat tomcat-centos 0bed71f53b94 52 minutes ago 612 MB
docker.io/centos latest 9f38484d220f 2 weeks ago 202 MB
[root@localhost software]# kubectl run myk8s-pod --image=base_tomcat --replicas=2 --port=80
deployment "myk8s-pod" created
[root@localhost software]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod-1394982580-11h8h 0/1 ContainerCreating 0 30s
myk8s-pod-1394982580-37wlc 0/1 ContainerCreating 0 30s
[root@localhost software]# kubectl run myk8s-pod-2 --image=base_tomcat --replicas=5 --port=8070
deployment "myk8s-pod-2" created
[root@localhost software]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod-1394982580-11h8h 0/1 ContainerCreating 0 2m
myk8s-pod-1394982580-37wlc 0/1 ContainerCreating 0 2m
myk8s-pod-2-2707079129-1305m 0/1 ContainerCreating 0 5s
myk8s-pod-2-2707079129-2nvff 0/1 ContainerCreating 0 5s
myk8s-pod-2-2707079129-dk9m5 0/1 ContainerCreating 0 5s
myk8s-pod-2-2707079129-mwn3g 0/1 ContainerCreating 0 5s
myk8s-pod-2-2707079129-r282t 0/1 ContainerCreating 0 5s
[root@localhost software]# kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
myk8s-pod 2 2 2 0 13m
myk8s-pod-2 5 5 5 0 11m
发现pod状态无论多久都是处于pending。READY字段一直是0/1,服务部署失败的原因是”中国墙“的问题导致无法下载pod启动时需要的谷歌镜像,所以我们得间接的创建所需的镜像。
补充: Pending状态表示API Server已经创建Pod,但Pod内还有一个或者多个容器没有创建,或者正在下载镜像的过程。详细的参考Pod声明周期和重启策略
查看pod信息
[root@localhost software]# kubectl describe pod myk8s-pod--11h8h
Name: myk8s-pod--11h8h
Namespace: default
Node: 127.0.0.1/127.0.0.1
Start Time: Fri, Mar :: +
Labels: pod-template-hash=
run=myk8s-pod
Status: Pending
IP:
Controllers: ReplicaSet/myk8s-pod-
Containers:
myk8s-pod:
Container ID:
Image: base_tomcat
Image ID:
Port: /TCP
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count:
Volume Mounts: <none>
Environment Variables: <none>
Conditions:
Type Status
Initialized True
Ready False
PodScheduled True
No volumes.
QoS Class: BestEffort
Tolerations: <none>
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
15m 15m {default-scheduler } Normal Scheduled Successfully assigned myk8s-pod--11h8h to 127.0.0.1
15m 4m {kubelet 127.0.0.1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request. details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)" 14m 11s {kubelet 127.0.0.1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with
ImagePullBackOff: "Back-off pulling image \"registry.access.redhat.com/rhel7/pod-infrastructure:latest\"" [root@localhost software]#
##百度 pod ContainerCreating
[root@localhost shell]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
Trying to pull repository registry.access.redhat.com/rhel7/pod-infrastructure ...
sha256:92d43c37297da3ab187fc2b9e9ebfb243c1110d446c783ae1b989088495db931: Pulling from registry.access.redhat.com/rhel7/pod-infrastructure
26e5ed6899db: Pull complete
66dbe984a319: Pull complete
9138e7863e08: Pull complete
Digest: sha256:92d43c37297da3ab187fc2b9e9ebfb243c1110d446c783ae1b989088495db931
Status: Image is up to date for registry.access.redhat.com/rhel7/pod-infrastructure:latest
##制作新镜像,因kubectl describe pod myk8s-pod-2-2707079129-1305m 提示找不到 docker.io/base-tomcat,那么我们就制作一个
[root@localhost registry.access.redhat.com]# docker tag base_tomcat:tomcat-centos docker.io/base-tomcat:v1
[root@localhost registry.access.redhat.com]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
base_tomcat tomcat-centos 0bed71f53b94 3 hours ago 612 MB
docker.io/base-tomcat v1 0bed71f53b94 3 hours ago 612 MB
docker.io/centos latest 9f38484d220f 2 weeks ago 202 MB
registry.access.redhat.com/rhel7/pod-infrastructure latest 99965fb98423 17 months ago 209 MB
[root@localhost registry.access.redhat.com]#
[root@localhost registry.access.redhat.com]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod-2-2707079129-1305m 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-2nvff 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-dk9m5 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-mwn3g 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-r282t 0/1 ImagePullBackOff 0 2h
[root@localhost registry.access.redhat.com]# kubectl run myk8s-pod-3 --image=docker.io/base-tomcat:v1 --replicas=3 --port=8060
deployment "myk8s-pod-3" created
[root@localhost registry.access.redhat.com]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod-2-2707079129-1305m 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-2nvff 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-dk9m5 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-mwn3g 0/1 ImagePullBackOff 0 2h
myk8s-pod-2-2707079129-r282t 0/1 ErrImagePull 0 2h
myk8s-pod-3-4228761222-5gdvr 1/1 Running 0 22s
myk8s-pod-3-4228761222-dngwc 1/1 Running 0 22s
myk8s-pod-3-4228761222-hl85l 1/1 Running
删除pod,再次查看pods,结果replication重新生成了一个pod myk8s-pod-1394982580-n8sv6 ,这样deployment myk8s-pod始终保持两个
[root@localhost software]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod-1394982580-11h8h / ContainerCreating 17m
myk8s-pod--37wlc / ContainerCreating 17m
myk8s-pod---1305m / ContainerCreating 15m
myk8s-pod---2nvff / ContainerCreating 15m
myk8s-pod---dk9m5 / ContainerCreating 15m
myk8s-pod---mwn3g / ContainerCreating 15m
myk8s-pod---r282t / ContainerCreating 15m
[root@localhost software]# kubectl delete myk8s-pod--11h8h
error: resource(s) were provided, but no name, label selector, or --all flag specified
[root@localhost software]# kubectl delete pod myk8s-pod--11h8h
pod "myk8s-pod-1394982580-11h8h" deleted
[root@localhost software]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod--37wlc / ContainerCreating 17m
myk8s-pod-1394982580-n8sv6 / ContainerCreating 4s
myk8s-pod---1305m / ContainerCreating 15m
myk8s-pod---2nvff / ContainerCreating 15m
myk8s-pod---dk9m5 / ContainerCreating 15m
myk8s-pod---mwn3g / ContainerCreating 15m
myk8s-pod---r282t / ContainerCreating 15m
[root@localhost software]#
删除部署myk8s-pod的服务,彻底删除pod
[root@localhost software]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod--37wlc / ContainerCreating 20m
myk8s-pod--n8sv6 / ContainerCreating 3m
myk8s-pod---1305m / ContainerCreating 18m
myk8s-pod---2nvff / ContainerCreating 18m
myk8s-pod---dk9m5 / ContainerCreating 18m
myk8s-pod---mwn3g / ContainerCreating 18m
myk8s-pod---r282t / ContainerCreating 18m
[root@localhost software]# kubectl delete deployment myk8s-pod
deployment "myk8s-pod" deleted
[root@localhost software]# kubectl get pods
NAME READY STATUS RESTARTS AGE
myk8s-pod---1305m / ContainerCreating 19m
myk8s-pod---2nvff / ContainerCreating 19m
myk8s-pod---dk9m5 / ContainerCreating 19m
myk8s-pod---mwn3g / ContainerCreating 19m
myk8s-pod---r282t / ContainerCreating 19m
[root@localhost software]# kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
myk8s-pod- 19m
centos7.5单机yum安装kubernetes的更多相关文章
- centos7下使用yum安装mysql
CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1. 下载mysql的repo源 wget http://repo.mysql.com/m ...
- CentOS7下使用YUM安装mariadb10
1:由于centos7 默认使用yum安装MySQL的话就会安装mariadb,只是安装的版本停留在mariadb5.x,版本比较低.如果我们需要安装mariadb10这里就需要删除mariadb-l ...
- centos7下使用yum安装pip
centos7下使用yum安装pip 首先安装epel扩展源: yum -y install epel-release 更新完成之后,就可安装pip: yum -y install python-pi ...
- <亲测>CentOS7中使用yum安装Nginx的方法
CentOS7中使用yum安装Nginx的方法 最近无意间发现Nginx官方提供了Yum源.因此写个文章记录下. 1.添加源 默认情况Centos7中无Nginx的源,最近发现Nginx官网提供了 ...
- centos7中使用yum安装tomcat以及它的启动、停止、重启
centos7中使用yum安装tomcat 介绍 Apache Tomcat是用于提供Java应用程序的Web服务器和servlet容器. Tomcat是Apache Software Foundat ...
- centos7下使用yum安装redis
centos7下使用yum安装Redis 第一步:安装 yum –y install redis 第二步:启动 systemctl start redis.service 第三步:设置开机启动 sys ...
- Centos7.6使用yum安装PHP7.2
Centos7.6使用yum安装PHP7.2 1.安装源 安装php72w,是需要配置额外的yum源地址的,否则会报错不能找到相关软件包. php高版本的yum源地址,有两部分,其中一部分是epel- ...
- centos7 hive 单机模式安装配置
前言:由于只是在自己的虚拟机上进行学习,所以对hive只是进行最简单的配置,其他复杂的配置文件没有配置. 1.前提 1.1 安装配置jdk1.8 1.2 安装hadoop2.x hadoop单机模式安 ...
- Centos7下yum安装kubernetes
一.前言 Kubernetes 是Google开源的容器集群管理系统,基于Docker构建一个容器的调度服务,提供资源调度.均衡容灾.服务注册.动态扩缩容等功能套件,目前centos yum源上 ...
随机推荐
- Python单元测试框架之pytest 4 -- 断言
From: https://www.cnblogs.com/fnng/p/4774676.html Python单元测试框架之pytest -- 断言 2015-08-31 23:57 by 虫师, ...
- PREV-2_蓝桥杯_打印十字图
问题描述 小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示: ..$$$$$$$$$$$$$....$...........$..$$$.$$$$$$$$$.$$$$...$...... ...
- STL基础--算法(已排序数据的算法,数值算法)
已排序数据的算法 Binary search, merge, set operations 每个已排序数据算法都有一个同名的更一般的形式 vector vec = {8,9,9,9,45,87,90} ...
- bzoj5011: [Jx2017]颜色
Description 可怜有一个长度为n的正整数序列Ai,其中相同的正整数代表着相同的颜色. 现在可怜觉得这个序列太长了,于是她决定选择一些颜色把这些颜色的所有位置都删去. 删除颜色i可以定义为把所 ...
- vc++使用cookie登录网站
以http://www.idc816.com为例 效果图: 1)先登录获取cookie,再使用cookie获取用户信息 2)记录cookie,关闭程序后重新运行程序,直接获取用户信息 使用Fiddle ...
- PAT 乙级 1009 说反话 (20) C++版
1009. 说反话 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定一句英语,要求你编写程序,将句中 ...
- Flink安装启动
1.下载安装包并解压 下载网址:https://flink.apache.org/ 版本选择可以根据安装的hadoop版本和Scala版本进行选择 我用的是:flink-1.3.3-bin-hadoo ...
- CVE-2017-12149漏洞利用
CVE-2017-12149 JBOOS AS 6.X 反序列化漏洞利用 这次分析一下 CVE-2017-12149 ,漏洞已经爆出有几天了,今天就把这个漏洞看一下. ...
- ORA-22922: 不存在的 LOB 值 可以使用外层嵌套wm_concat()解决
select kw0408id, sjbh, ksrs, kch, to_char(wm_concat(kcmc)) as kcmc, ksxs, kssc, ksfs, kcxz, xsyx, nj ...
- 十三篇系列:king转折点,wooga瓶颈,supercell营收结构
转自:http://gamerboom.com/archives/95125 十三篇系列:king的历史转折点,wooga的瓶颈,supercell的营收结构 第一篇 这句话In other word ...