使用VMware设置ip:192.168.8.32
菜单
一、安装docker。这不描述了,具体请查看本blog的文章
二、修改docker/ daemon.json
shell>sudo usermod -aG docker $USER
shell>newgrp docker
允许openshirt的172.30.0.0/16不安全访问。docker要求https
shell>sudo tee /etc/docker/daemon.json<<EOF
{
"insecure-registries": [
"172.30.0.0/16"
]
}
EOF
shell>sudo systemctl daemon-reload
shell>sudo systemctl restart docker
shell>sudo systemctl enable docker
三、开启IP转发
shell>echo "net.ipv4.ip_forward = 1" | sudo tee -a /etc/sysctl.conf
shell>sudo sysctl -p
四、设置防火墙
确保你的防火墙允许容器访问OpenShift主API (8443/tcp)和DNS (53/udp)端点
shell>systemctl stop firewalld
shell>DOCKER_BRIDGE=`docker network inspect -f "{{range .IPAM.Config }}{{ .Subnet }}{{end}}" bridge`
shell>sudo firewall-cmd --permanent --new-zone dockerc
shell>sudo firewall-cmd --permanent --zone dockerc --add-source $DOCKER_BRIDGE
shell>sudo firewall-cmd --permanent --zone dockerc --add-port={80,443,8443}/tcp
shell>sudo firewall-cmd --permanent --zone dockerc --add-port={53,8053}/udp
shell>sudo firewall-cmd --reload
五、下载openshift并解压
shell>wget https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
shell>tar xvf openshift-origin-server-v3.11.0-0cbc58b-linux-64bit.tar.gz
shell>mkdir -p /data/app
shell>mv openshift-origin-server-v3.11.0-0cbc58b-linux-64bit /data/app/openshift
配置环境:
- 开启SELINUX
###shell>vim /etc/selinux/config
SELINUX=enforcing
SELINUXTYPE=targeted
- 配置主机名
shell>hostnamectl set-hostname master
- 修改环境变量 vim /etc/profile 在后面追加下面内容
PATH=$PATH:/data/app/openshift
#不加login登录会有点问题
export KUBECONFIG=/data/app/openshift/openshift.local.config/master/admin.kubeconfig
export CURL_CA_BUNDLE=/data/app/openshift/openshift.local.config/master/ca.crt
- 执行source使修改的指令生效
# source /etc/profile
- 验证
# openshift version
启动OpenShift
shell> oc cluster up
此时宿主机访问:https://192.168.8.32:8443/console/
然后会自动跳转至https://127.0.0.1:8443/*****,只需要把IP修改成192.168.8.32即可继续访问
如何解决上述问题:
方法一:修改 OCP 配置文件
记得需要先关闭再启动
shell>oc cluster down
shell>vim /data/app/openshift/openshift.local.clusterup/openshift-controller-manager/openshift-master.kubeconfig
################## 将修改“server: https://127.0.0.1:8443
server: https://192.168.8.32:8443
shell>oc cluster up
方法二:设置hostpath
oc cluster up --routing-suffix=<ServerPublicIP>.xip.io \ --public-hostname=<ServerPulicDNSName>
- –public-hostname 指定后续 DNS 映射的域名[访问openshirt的地址]
- –routing-suffix 指定部署服务的域名后缀,如 services.shiftdemo.com【部署app的后缀,可继续看文章后续】
shell>oc cluster up --public-hostname=okd.shiftdemo.com --routing-suffix='services.shiftdemo.com'
如果正常配置的话,会得到以下的信息
shell> oc cluster status
Web console URL: https://okd.example.com:8443/console/
Config is at host directory
Volumes are at host directory
Persistent volumes are at host directory /home/dev/openshift.local.clusterup/openshift.local.pv
Data will be discarded when cluster is destroyed
vim /etc/hosts 添加“192.168.8.32 okd.shiftdemo.com”
在windows修改hosts:C:\Windows\System32\drivers\etc\hosts
,添加 192.168.8.32 okd.shiftdemo.com
如果出现设置public-hostname还是显示127.0.0.1
- oc cluster down
- delete the openshift.local.clusterup directory rm -rf openshift.local.clusterup
- redeploy the cluster ov cluster up –public-hostname= <IP or hostname>
go to http://ip:8443/console
openshift常见命令
1、用管理员登录
[root@master ~]# oc login -u system:admin
Logged into "https://127.0.0.1:8443" as "system:admin" using existing credentials.
You have access to the following projects and can switch between them with 'oc project <projectname>':
default
kube-dns
kube-proxy
kube-public
kube-system
* myproject
openshift
openshift-apiserver
openshift-controller-manager
openshift-core-operators
openshift-infra
openshift-node
openshift-service-cert-signer
openshift-web-console
Using project "myproject".
登录管理员后,可以通过 get node查看节点的信息
[root@master ~]# oc get nodes
NAME STATUS ROLES AGE VERSION
localhost Ready <none> 23h v1.11.0+d4cacc0
[root@master ~]# oc get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
localhost Ready <none> 23h v1.11.0+d4cacc0 192.168.8.32 <none> CentOS Linux 7 (Core) 3.10.0-1160.el7.x86_64 docker://20.10.8
获取指定节点的详细信息
[root@master ~]# oc describe node localhost
查看已安装的资源
[root@master ~]# oc status
In project My Project (myproject) on server https://127.0.0.1:8443
You have no services, deployment configs, or build configs.
Run 'oc new-app' to create an application.
=========(因为还没创建app)
切换开发者账号
$ oc login Authentication required forhttps://127.0.0.1:8443 (openshift) Username: developer Password: developer Login successful.
确认是否登录成功/查看当前openshirt登录用户
$ oc whoami
developer
创建新的项目(Project)
$ oc new-project dev --display-name="Project1 - Dev" \ --description="My Dev Project" Now using project "dev" on server "https://127.0.0.1:8443".
创建一个新的应用
从Docker Hub注册表标记一个应用程序映像
shell> oc tag --source=docker openshift/deployment-example:v2 deployment-example:v88 shell> oc new-app deployment-example:v88
查看已安装的源
[root@master ~]# oc status
In project Project1 - Dev (dev) on server https://127.0.0.1:8443
svc/deployment-example - 172.30.205.30:8080
dc/deployment-example deploys istag/deployment-example:v88
deployment #1 deployed about a minute ago - 1 pod
2 infos identified, use 'oc status --suggest' to see details
获得详细的service信息
[root@master ~]# oc get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
deployment-example ClusterIP 172.30.205.30 <none> 8080/TCP 3m
[root@master ~]#
[root@master ~]#
[root@master ~]# oc describe svc deployment-example
Name: deployment-example
Namespace: dev
Labels: app=deployment-example
Annotations: openshift.io/generated-by=OpenShiftNewApp
Selector: app=deployment-example,deploymentconfig=deployment-example
Type: ClusterIP
IP: 172.30.205.30
Port: 8080-tcp 8080/TCP
TargetPort: 8080/TCP
Endpoints: 172.17.0.10:8080
Session Affinity: None
Events: <none>
测试应用是否能访问
shell>curl http://172.30.205.30:8080
获得pod的状态
[root@master ~]# oc get pods
NAME READY STATUS RESTARTS AGE
deployment-example-1-z99fd 1/1 Running 0 5m
允许外部链接访问
[root@master ~]# oc expose service/deployment-example
route.route.openshift.io/deployment-example exposed
[root@master ~]# oc get routes
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
deployment-example deployment-example-dev.services.shiftdemo.com deployment-example 8080-tcp None
[root@master ~]#
None
上文提及 –public-hostname 和 –routing-suffix
然后设置windows的hosts
删除测试应用
$ oc delete all -l app=deployment-example pod "deployment-example-1-8n8sd" deleted replicationcontroller "deployment-example-1" deleted service "deployment-example" deleted deploymentconfig.apps.openshift.io "deployment-example" deleted route.route.openshift.io "deployment-example" deleted $ oc get pods No resources found.
文章参考:https://computingforgeeks.com/setup-openshift-origin-local-cluster-on-centos/