1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 12:46:18 +01:00
Files
openshift-docs/modules/osdk-run-deployment.adoc
2023-10-30 10:13:25 -04:00

184 lines
5.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Module included in the following assemblies:
//
// * operators/operator_sdk/golang/osdk-golang-tutorial.adoc
// * operators/operator_sdk/ansible/osdk-ansible-tutorial.adoc
// * operators/operator_sdk/ansible/osdk-ansible-inside-operator.adoc
// * operators/operator_sdk/helm/osdk-helm-tutorial.adoc
ifeval::["{context}" == "osdk-golang-tutorial"]
:golang:
endif::[]
ifeval::["{context}" == "osdk-java-tutorial"]
:java:
endif::[]
:_mod-docs-content-type: PROCEDURE
[id="osdk-run-deployment_{context}"]
ifeval::["{context}" != "osdk-ansible-inside-operator"]
= Running as a deployment on the cluster
endif::[]
ifeval::["{context}" == "osdk-ansible-inside-operator"]
= Testing an Ansible-based Operator on the cluster
After you have tested your custom Ansible logic locally inside of an Operator, you can test the Operator inside of a pod on an {product-title} cluster, which is preferred for production use.
endif::[]
You can run your Operator project as a deployment on your cluster.
ifdef::golang[]
.Prerequisites
* Prepared your Go-based Operator to run on {product-title} by updating the project to use supported images
endif::[]
.Procedure
. Run the following `make` commands to build and push the Operator image. Modify the `IMG` argument in the following steps to reference a repository that you have access to. You can obtain an account for storing containers at repository sites such as Quay.io.
.. Build the image:
+
[source,terminal]
----
$ make docker-build IMG=<registry>/<user>/<image_name>:<tag>
----
+
[NOTE]
====
The Dockerfile generated by the SDK for the Operator explicitly references `GOARCH=amd64` for `go build`. This can be amended to `GOARCH=$TARGETARCH` for non-AMD64 architectures. Docker will automatically set the environment variable to the value specified by `platform`. With Buildah, the `build-arg` will need to be used for the purpose. For more information, see link:https://sdk.operatorframework.io/docs/advanced-topics/multi-arch/#supporting-multiple-architectures[Multiple Architectures].
====
.. Push the image to a repository:
+
[source,terminal]
----
$ make docker-push IMG=<registry>/<user>/<image_name>:<tag>
----
+
[NOTE]
====
The name and tag of the image, for example `IMG=<registry>/<user>/<image_name>:<tag>`, in both the commands can also be set in your Makefile. Modify the `IMG ?= controller:latest` value to set your default image name.
====
ifdef::java[]
. Run the following command to install the CRD to the default namespace:
+
[source,terminal]
----
$ oc apply -f target/kubernetes/memcacheds.cache.example.com-v1.yml
----
+
.Example output
[source,terminal]
----
customresourcedefinition.apiextensions.k8s.io/memcacheds.cache.example.com created
----
. Create a file called `rbac.yaml` as shown in the following example:
+
[source,yaml]
----
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: memcached-operator-admin
subjects:
- kind: ServiceAccount
name: memcached-quarkus-operator-operator
namespace: <operator_namespace>
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: ""
----
+
[IMPORTANT]
====
The `rbac.yaml` file will be applied at a later step.
====
endif::[]
. Run the following command to deploy the Operator:
+
[source,terminal]
----
$ make deploy IMG=<registry>/<user>/<image_name>:<tag>
----
ifeval::["{context}" != "osdk-java-tutorial"]
+
By default, this command creates a namespace with the name of your Operator project in the form `<project_name>-system` and is used for the deployment. This command also installs the RBAC manifests from `config/rbac`.
endif::[]
ifdef::java[]
. Run the following command to grant `cluster-admin` privileges to the `memcached-quarkus-operator-operator` by applying the `rbac.yaml` file created in a previous step:
+
[source,terminal]
----
$ oc apply -f rbac.yaml
----
endif::[]
. Run the following command to verify that the Operator is running:
+
ifeval::["{context}" != "osdk-java-tutorial"]
[source,terminal]
----
$ oc get deployment -n <project_name>-system
----
+
.Example output
[source,terminal]
----
NAME READY UP-TO-DATE AVAILABLE AGE
<project_name>-controller-manager 1/1 1 1 8m
----
endif::[]
ifdef::java[]
[source,terminal]
----
$ oc get all -n default
----
+
.Example output
[source,terminal]
----
NAME READY UP-TO-DATE AVAILABLE AGE
pod/memcached-quarkus-operator-operator-7db86ccf58-k4mlm 0/1 Running 0 18s
----
. Run the following command to apply the `memcached-sample.yaml` and create the `memcached-sample` pod:
+
[source,terminal]
----
$ oc apply -f memcached-sample.yaml
----
+
.Example output
[source,terminal]
----
memcached.cache.example.com/memcached-sample created
----
.Verification
* Run the following command to confirm the pods have started:
+
[source,terminal]
----
$ oc get all
----
+
.Example output
[source,terminal]
----
NAME READY STATUS RESTARTS AGE
pod/memcached-quarkus-operator-operator-7b766f4896-kxnzt 1/1 Running 1 79s
pod/memcached-sample-6c765df685-mfqnz 1/1 Running 0 18s
----
endif::[]
ifeval::["{context}" == "osdk-golang-tutorial"]
:!golang:
endif::[]
ifeval::["{context}" == "osdk-java-tutorial"]
:!java:
endif::[]