当前位置:网站首页>Openshift deployment application
Openshift deployment application
2022-07-02 08:36:00 【freesharer】
OpenShift Deploy the application
openshift Support the following ways to create applications
- Create applications from images
- Create an application from source code
- Create an application from a template
OpenShift Create user
Openshift After cluster deployment , There is one. kubeadmin The default user , But you can't edit and change the password , Therefore, the best practice and solution is to create a new user and upgrade the user's permission to cluster-admin
, Convenient for subsequent login console.
stay OpenShift Use identity providers in (identity provider ) To authenticate , Therefore, you need to choose one before creating users identity provider, The simplest provider is htpasswd,htpasswd Just a simple file , Include user name and password , It does not require any complicated installation or setup .
Here's how to use htpasswd The provider is OpenShift The cluster creates some administrator users . It is not recommended to set this authentication method in the production cluster , It's not safe . Users cannot easily change their passwords in this way , And any administrator can enter and read htpasswd The content of the document .
1、 establish htpasswd Document and OAuth Provider ,ubuntu Default by oneself htpasswd
command
First , Create an empty htpasswd file , The following operations are bastion Node execution .
touch htpasswd
2、 Next , Use htpasswd
The command adds the user and password to the file .
htpasswd -Bb htpasswd admin Openshift#123
3、 stay openshift-config
Create a Secret . This includes htpasswd The full content of the document , In order to OpenShift You can read it to verify the user name and password :
oc --user=admin create secret generic htpasswd \
--from-file=htpasswd \
-n openshift-config
4、 Now create in the cluster OAuth Custom resources , Configure only 1 individual Identity provider htpasswd. This refers to the one just created above Secret :
oc replace -f - <<API apiVersion: config.openshift.io/v1 kind: OAuth metadata: name: cluster spec: identityProviders: - name: Local Password mappingMethod: claim type: HTPasswd htpasswd: fileData: name: htpasswd API
5、 Create a group for administrator users :
oc adm groups new mylocaladmins
6、 Add users to groups :
oc adm groups add-users mylocaladmins admin
7、 Log back in OpenShift Console, There are many login methods , choice Local Password, Enter the username and password :admin Openshift#123 Log in .
After logging in again , You can see that a new one has been created admin user
OpenShift Use deployment to create applications
1、 Projects allow users to organize and manage their content in separate spaces , But in part openshift- and kube- The first item is the default item , Run the system components of the cluster ,openshift It is not recommended or restricted that users run under these projects pod Or service .
Create a new project first , Namespace , Switch to the Project menu bar , Here we use demo Project as an example
2、 Click deploy in the workload , Switch to the one created above demo project , Click Create deployment , namely deployment Application of type
3、 Modification example yaml To configure , Note that the image must be nonroot type , And can't listen 1024 The following ports , Choose here dockerhub Upper bitnami nginx Mirror image .
apiVersion: apps/v1
kind: Deployment
metadata:
name: example
namespace: demo
spec:
selector:
matchLabels:
app: nginx
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: >-
bitnami/nginx:1.20.2
ports:
- containerPort: 8080
4、 Click create , wait for pod Status as running
5、 Create services for deployed applications , Switch to the network , Click Service , Create services
modify yaml For , Pay attention to revision selector And port , Be consistent with the deployed application
apiVersion: v1
kind: Service
metadata:
name: example
namespace: demo
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 8080
targetPort: 8080
6、 Finally, create a route for the deployed application , To access outside the cluster
The configuration is as follows , The host name is consistent with the initial planning of the cluster , The domain name format is :*.apps.okd4.example.com
After the route is created, it is shown as follows , Click the location to directly access
7、 Or manually enter the routing address in the browser to access the application :http://example.apps.okd4.example.com/
8、 You can also use the command mode to deploy the application from the specified image , Appoint dockerhub Upper nginx Mirror image
[email protected]:~# oc new-app --image=docker.io/bitnami/nginx:1.20.2
--> Found container image ec80aa6 (3 hours old) from docker.io for "docker.io/bitnami/nginx:1.20.2"
* An image stream tag will be created as "nginx:1.20.2" that will track this image
--> Creating resources ...
imagestream.image.openshift.io "nginx" created
deployment.apps "nginx" created
service "nginx" 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 service/nginx'
Run 'oc status' to view your app.
Automatically create deployment and service, But you need to manually create routes to expose applications outside the cluster
[email protected]:~# oc expose service/nginx
route.route.openshift.io/nginx exposed
OpenShift Use the development perspective to create applications
1、 Switch to the developer perspective , Click Add , Select container mirror
2、 Mirror selection dockerhub Mirror image :docker.io/bitnami/nginx:1.20.2
You can also choose The image stream label of the internal container image warehouse
, You need to create a mirror stream in advance , The mirror stream label points to dockerhub A mirror image in .
oc import-image nginx-app \
--from=docker.io/bitnami/nginx:1.20.2 \
--confirm
After configuration, click Create .
3、 Switch to topology , Click on the open URL Visit
Browser access is as follows :
边栏推荐
- ARP及ARP欺骗
- idea中注释代码取消代码的快捷键
- Matlab - autres
- Zipkin is easy to use
- The best blog to explain the basics of compilation (share)
- Jumping | Blue Bridge Cup
- Causes of laptop jam
- HCIA—应用层
- C language custom type enumeration, Union (clever use of enumeration, calculation of union size)
- Using C language to realize MySQL true paging
猜你喜欢
旋转链表(图解说明)
Sentinel 简单使用
Use of opencv3 6.2 low pass filter
群辉 NAS 配置 iSCSI 存储
How to build the alliance chain? How much is the development of the alliance chain
2022 Heilongjiang's latest eight member (Safety Officer) simulated test question bank and answers
Luogu greedy part of the backpack line segment covers the queue to receive water
双向链表的实现(双向链表与单向链表的简单区别联系和实现)
Sqli labs (post type injection)
Jumping | Blue Bridge Cup
随机推荐
Opencv's experience of confusing X and Y coordinates
One of the reasons for WCF update service reference error
What is SQL injection
idea中注释代码取消代码的快捷键
Live broadcast platform development, flexible menu, and freely adjust the horizontal size of the menu bar
使用wireshark抓取Tcp三次握手
Learning C
Call Stack
Force deduction method summary: double pointer
Don't know mock test yet? An article to familiarize you with mock
ICMP Protocol
Smart agriculture solutions smart agriculture system development
Carsim problem failed to start Solver: Path Id Obj (X) was set to y; Aucune valeur de correction de xxxxx?
路由基础—动态路由
Routing foundation - dynamic routing
HackTheBox-Gunship
C language replaces spaces in strings with%20
Getting started with k8s: building MySQL with Helm
[blackmail virus data recovery] suffix Rook3 blackmail virus
Analysis of the use of comparable, comparator and clonable interfaces