因为在OpenShift 4.1环境中不建议直接登录集群主机操作,因此很多操作可能需要在外部的Client VM上完成。当然用rhel的worker node的同事也可以和原来习惯保持一致。

这里记录一下经常遇到的一些问题:

  • 如何查看密码

在4.1集群安装完后,系统会打印一句话出来,比如

INFO Creating infrastructure resources...         *********************************************************************************************
INFO Waiting up to 30m0s for the Kubernetes API at https://api.cluster-8447.sandbox.opentlc.com:6443...
INFO API v1.13.4+3a25c9b up
INFO Waiting up to 30m0s for bootstrapping to complete...
INFO Destroying the bootstrap resources...
INFO Waiting up to 30m0s for the cluster at https://api.cluster.sandbox.opentlc.com:6443 to initialize...
INFO Waiting up to 10m0s for the openshift-console route to be created...
INFO Install complete!
INFO To access the cluster as the system:admin user when using 'oc', run 'export KUBECONFIG=/root/cluster/auth/kubeconfig'
INFO Access the OpenShift web-console here: https://console-openshift-console.apps.cluster.sandbox.opentlc.com
INFO Login to the console with user: kubeadmin, password: TyCzM-ShJPQ-cgepT-dkDwq

一定要拷贝出来啊。。。如果万一没有拷贝,那在哪里还能找到呢?

可以在安装目录(cluster名)下,有个叫.openshift_install.log的文件,在那里可以找到

  • 设置集群访问

export KUBECONFIG=$HOME/cluster-${GUID}/auth/kubeconfig
echo "export KUBECONFIG=$HOME/cluster-${GUID}/auth/kubeconfig" >>$HOME/.bashrc
  • 上传镜像到内部镜像仓库

暴露image-registry路由,缺省不暴露route,只暴露image-registry.openshift-image-registry.svc服务

[root@clientvm  ~]# oc get svc -n openshift-image-registry
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
image-registry ClusterIP 172.30.134.180 <none> /TCP 5h2m
oc patch configs.imageregistry.operator.openshift.io/cluster --patch '{"spec":{"defaultRoute":true}}' --type=merge

Podman登录

oc login -u kubeadm

HOST=$(oc get route default-route -n openshift-image-registry --template='{{ .spec.host }}')
podman login -u kubeadm -p $(oc whoami -t) --tls-verify=false $HOST

胡乱搞了一个Dockerfile,然后build

podman build -t default-route-openshift-image-registry.apps.cluster-.sandbox452.opentlc.com/myproject/mytomcat:slim .
[root@clientvm  ~/cluster-]# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
default-route-openshift-image-registry.apps.cluster-.sandbox452.opentlc.com/myproject/mytomcat slim ec32b2cdbea2 About a minute ago MB
<none> <none> 0426c1689356 minutes ago MB
docker.io/library/openjdk -jdk 08ded5f856cc days ago MB

然后push镜像,切记使用--tls-verify=false

[root@clientvm  ~]# podman push default-route-openshift-image-registry.apps.cluster-d60b.sandbox509.opentlc.com/myproject/mytomcat:slim --tls-verify=false
Getting image source signatures
Copying blob ea23cfa0bea9 done
Copying blob 2bf534399aca done
Copying blob eb25e0278d41 done
Copying blob 46ff59048438 done
Copying blob f613cd1e50cc done
Copying blob 1c95c77433e8 done
Copying blob 6d520b2e1077 done
Copying config done
Writing manifest to image destination
Copying config done
Writing manifest to image destination
Storing signatures

push完可以看到imagestream

生成应用

[root@clientvm  ~/cluster-]# oc new-app mytomcat:slim
--> Found image ec32b2c ( minutes old) in image stream "myproject/mytomcat" under tag "slim" for "mytomcat:slim" * This image will be deployed in deployment config "mytomcat"
* Port /tcp will be load balanced by service "mytomcat"
* Other containers can access this service through the hostname "mytomcat"
* WARNING: Image "myproject/mytomcat:slim" runs as the 'root' user which may not be permitted by your cluster administrator --> Creating resources ...
deploymentconfig.apps.openshift.io "mytomcat" created
service "mytomcat" created
--> Success
Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
'oc expose svc/mytomcat'
Run 'oc status' to view your app.

通过命令可以直接部署,但如果在deployment.yaml中间的image直接写myproject/mytomcat会出错的。

如果是自己建立模板和通过yaml文件部署,image字段的正确写法是全路径。

image-registry.openshift-image-registry.svc:/openshift/mytomcat:-slim
  • 添加用户

OpenShift 4.1 的用户认证这块也基于Operator实现,和3.11很大的区别在于3.11是配置在master-config.yaml下面,缺省是HTPasswd,

而4是缺省identity provider是没有的,需要基于authentication的cr配置出来。

在Cluster Setting的Global Configuration里面可以看到OAuth这项内容。

点击进去可以看到identity Provider为空

缺省只能用kubeadmin登录,如果需要添加用户,首先需要创建CR(Custom Resource)

如果我们还是以原来的HTPasswd方式,步骤如下:

1.在客户端创建users.htpasswd文件,并写入用户

htpasswd -c -B -b users.htpasswd admin welcome1

如果要添加多个用户,用下面命令

htpasswd -b users.htpasswd eric welcome1
htpasswd -b users.htpasswd alice welcome1

2. 在openshift-config下创建secret

oc create secret generic htpass-secret --from-file=htpasswd=/root/users.htpasswd -n openshift-config

如果是以后在文件中又添加了用户,可以用下面命令更新

oc create secret generic htpass-secret --from-file=htpasswd=/root/users.htpasswd -n openshift-config --dry-run -o yaml | oc apply -f -

完成后可以在openshift-config下看到这个secret, 选择edit secret,看到里面包含得用户名

3. 更新CR, 写一个yaml文件, 这一步也可以直接在界面上添加。

[root@clientvm  ~]# cat htpass.yaml
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: my_htpasswd_provider
mappingMethod: claim
type: HTPasswd
htpasswd:
fileData:
name: htpass-secret

cluster的CR已经存在,所有通过apply去更新

[root@clientvm  ~]# oc apply -f htpass.yaml
Warning: oc apply should be used on resource created by either oc create --save-config or oc apply
oauth.config.openshift.io/cluster configured

完成后可以看到在Oauth里面包含了一个my_htpasswd_provider

检查Pod的状态(在openshift-authentication project下),如果没有重新更新,就手工delete Pod让他重新装载一遍.

用oc get users看一看,怎么什么都没有。。。这里有个坑,只有登录过后的用户才能看到,所以直接登录吧

[root@clientvm  ~]# oc login -u eric
Authentication required for https://api.cluster-8447.sandbox452.opentlc.com:6443 (openshift)
Username: eric
Password:
Login successful. You don't have any projects. You can try to create a new project, by running oc new-project <projectname>

再切换回 kubeadmin用户,就可以看到了

[root@clientvm  ~]# oc get users
NAME UID FULL NAME IDENTITIES
admin 463b2706-c3d9-11e9-b6ad-0a580a81001f my_htpasswd_provider:admin
alice d73b3e6f-c3db-11e9-ba6d-0a580a80001a my_htpasswd_provider:alice
eric 4c8b7952-c3de-11e9-ab5a-0a580a82001b my_htpasswd_provider:eric

设置为集群管理员

oc adm policy add-cluster-role-to-user cluster-admin admin

Console上LogOut

鼠标点击选择my_htpasswd_provider,一定要选这个,如果选上面的是不会让你登录的,然后用用户名登录就可以了。

OpenShift 4.1 基本问题探索的更多相关文章

  1. RedHat OpenShift QuickStart 1.1 OpenShift基础

    openshift 提供了命令行工具和web可视化页面,这些工具通过REST API去和openshift交互 一.开始为开发人员使用OpenShift 1. 探索命令行 2. 探索web conso ...

  2. [转]OpenShift 集群搭建指南

    转自:http://www.cnblogs.com/zhangning/p/7251810.html OpenShift 集群搭建指南 v1.0 搭建Hyper-v虚拟机或物理机 配置物理机静态IP, ...

  3. 在OpenShift平台上验证NVIDIA DGX系统的分布式多节点自动驾驶AI训练

    在OpenShift平台上验证NVIDIA DGX系统的分布式多节点自动驾驶AI训练 自动驾驶汽车的深度神经网络(DNN)开发是一项艰巨的工作.本文验证了DGX多节点,多GPU,分布式训练在DXC机器 ...

  4. 【探索】机器指令翻译成 JavaScript

    前言 前些时候研究脚本混淆时,打算先学一些「程序流程」相关的概念.为了不因太枯燥而放弃,决定想一个有趣的案例,可以边探索边学. 于是想了一个话题:尝试将机器指令 1:1 翻译 成 JavaScript ...

  5. 【探索】利用 canvas 实现数据压缩

    前言 HTTP 支持 GZip 压缩,可节省不少传输资源.但遗憾的是,只有下载才有,上传并不支持.如果上传也能压缩,那就完美了.特别适合大量文本提交的场合,比如博客园,就是很好的例子. 虽然标准不支持 ...

  6. 探索C#之6.0语法糖剖析

    阅读目录: 自动属性默认初始化 自动只读属性默认初始化 表达式为主体的函数 表达式为主体的属性(赋值) 静态类导入 Null条件运算符 字符串格式化 索引初始化 异常过滤器when catch和fin ...

  7. Mysql事务探索及其在Django中的实践(二)

    继上一篇<Mysql事务探索及其在Django中的实践(一)>交代完问题的背景和Mysql事务基础后,这一篇主要想介绍一下事务在Django中的使用以及实际应用给我们带来的效率提升. 首先 ...

  8. Linux学习之探索文件系统

    Linux,一起学习进步-    ls With it, we can see directory contents and determine a variety of important file ...

  9. 马里奥AI实现方式探索 ——神经网络+增强学习

    [TOC] 马里奥AI实现方式探索 --神经网络+增强学习 儿时我们都曾有过一个经典游戏的体验,就是马里奥(顶蘑菇^v^),这次里约奥运会闭幕式,日本作为2020年东京奥运会的东道主,安倍最后也已经典 ...

随机推荐

  1. 如何进行SQL注入攻击?

    1.数字注入 2.字符串注入 3. #后边全部为注释,字符串拼装后绕过密码验证. 4. 同样绕过密码验证

  2. 关于python模块总结

    名词解释 模块(module):在python中,一个.py文件就是一个模块 包(package):为了避免模块名冲突,Python又引入了按目录来组织模块的方法.当目录下存在__init__.py, ...

  3. 微信小程序~跳页传参

    [1]需求: 点击商品,跳到相应商品详情页面 [2]代码: (1)商品列表页 <view class="goodsList"> <view wx:for=&quo ...

  4. Kafka为什么这么快?

    批量处理 传统消息中间件的消息发送和消费整体上是针对单条的.对于生产者而言,它先发一条消息,然后broker返回ACK表示已接收,这里产生2次rpc:对于消费者而言,它先请求接受消息,然后broker ...

  5. May Cook-Off 2019 解题报告

    太气了.Atcoder unrated了. 这一场时间太不友好了.昨天下午一时兴起就去补了一发.题很好,学到好多东西. Chain Reaction 题意:给一个矩阵,这个矩阵是稳定的当且仅当每一个元 ...

  6. selenium原理解析

    相信很多测试小伙伴儿都听过或者使用过web自动化selenium,那您有没有研究过selenium的原理呢?为什么要使用webdriver.exe,webdriver.exe是干啥用的?seleniu ...

  7. 阿里巴巴编程规约--digest

    所谓卫语句,如果某个条件极其罕见,就应该单独检查该条件,并在该条件为真时立刻从函数中返回.这样的单独检查常常被称为“卫语句”. 微服务之间将DTO,Req放到一个单独的项目中,相关的项目都依赖这个底层 ...

  8. LG1036

    当我们看到这道题的时候,我们不仅大吼一声,这不就是搜索嘛. 于是搜索两大刀!搜索目标和搜索状态! 搜索目标:求选数的方案,以及他们的和是否为质数. 搜索状态: 1.从后往前分析目标(或从前往后):和是 ...

  9. am335x system upgrade set/get current cpufreq(二十一)

    1      Scope of Document This document describes am335x cpufreq technology insider. 2      Requireme ...

  10. 洛谷 P2563 [AHOI2001]质数和分解 题解

    P2563 [AHOI2001]质数和分解 题目描述 任何大于 1 的自然数 n 都可以写成若干个大于等于 2 且小于等于 n 的质数之和表达式(包括只有一个数构成的和表达式的情况),并且可能有不止一 ...