1 關(guān)防火墻
systemctl disable firewalld
systemctl stop firewalld
- 關(guān)selinux
vim /etc/selinux/config
SELINUX=disabled - 安裝etcd kubernetes(會自動安裝docker)
yum install -y etcd kubernetes - 安裝好軟件后急鳄,修改2個配置文件
4.1 /etc/sysconfig/docker,其中options的內(nèi)容配置為:
OPTIONS='--selinux-enabled=false --insecure-registry gcr.io'
4.2 /etc/kubernetes/apiserver,把admission-control中的ServiceAccount去掉 - 按順序啟動所有的服務(wù)
for i in etcd docker kube-apiserver kube-controoler-manager kube-scheduler kubelet kube-proxy;do systemctl start i;systemctl status $i;done - 執(zhí)行以下步驟
1 wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm
2 rpm2cpio python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm | cpio -iv --to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem
3 docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
4 for i in flanneld kube-proxy kubelet docker;do systemctl restart $i;systemctl enable $i;systemctl status $i ;done
iptables -P FORWARD ACCEPT
到這里凹嘲,單機版的kubernetes集群環(huán)境就安裝啟動完成了
現(xiàn)在開始練習在k8s里啟動一個服務(wù)
創(chuàng)建一個目錄k8straining,以下操作都在k8straining目錄里
- 先啟動一個mysql,先創(chuàng)建一個rc定義文件:mysql-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: mysql
spec:
replicas: 1
selector:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.7
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "123456"
執(zhí)行kubectl create -f mysql-rc.yaml 創(chuàng)建rc
查看rc: kubectl get rc
查看pod: kubectl get pod
創(chuàng)建一個mysql的kubernetes service,先創(chuàng)建一個mysql-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- port: 3306
selector:
app: mysql
創(chuàng)建service: kubectl create -f mysql-svc.yaml
查看service: kubectl get svc
- 啟動tomcat應(yīng)用,先創(chuàng)建myweb-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: myweb
spec:
replicas: 5
selector:
app: myweb
template:
metadata:
labels:
app: myweb
spec:
containers:
- name: myweb
image: kubeguide/tomcat-app:v1
ports:
- containerPort: 8080
env:
- name: MYSQL_ROOT_HOST
value: "mysql"
- name: MYSQL_ROOT_PORT
value: '3306'
創(chuàng)建rc: kubectl create -f myweb-rc.yaml
應(yīng)用service配置文件 myweb-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: myweb
spec:
type: NodePort
ports:
- port: 8080
nodePort: 30001
selector:
app: myweb
kubectl create -f myweb-svc.yaml
查看創(chuàng)建的service
kubectl get service
在本機瀏覽器看效果: