-
Notifications
You must be signed in to change notification settings - Fork 429
UCP Client‐Server Example on Kubernetes Cluster
The page describes a deployment of UCP client-server example on a Kubernetes cluster.
You need to setup Kubernetes first. The setup guide can be found here.
We will need an image to make the deployment. This is an example of the dockerfile to create the image with UCX library and UCP client-server example.centos7-ucp-client-server.dockerfile
FROM centos:7
RUN yum install -y \
autoconf \
automake \
gcc-c++ \
git \
libtool \
make
RUN git clone --depth 1 --branch v1.16.0 https://github.com/openucx/ucx.git
WORKDIR /ucx/
RUN ./autogen.sh
WORKDIR /ucx/build
RUN ../contrib/configure-release --prefix=$PWD/../install
RUN make -j install
ENV PATH="${PATH}:/ucx/install/bin"
ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/ucx/install/lib"
ENV C_INCLUDE_PATH="${C_INCLUDE_PATH}:/ucx/install/include"
ENV LIBRARY_PATH="${LIBRARY_PATH}:/ucx/install/lib"
WORKDIR /ucx
RUN gcc examples/ucp_client_server.c -lucp -lucs -o /ucx/install/bin/ucp_client_server
We will use the image based on this dockerfile, with tag images/centos7-ucp-client-server
. This is the command line to build the image.
$ docker build -t images/centos7-ucp-client-server - < centos7-ucp-client-server.dockerfile
Please do not forget to push the image to the registry you are using if you want to use the image. E.g. if you use minikube, you can load image locally using the following command.
$ minikube image load images/centos7-ucp-client-server
The server part is created as a deployment.
ucp-server-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: ucp-server-deployment
labels:
app: ucp-server
spec:
replicas: 1
selector:
matchLabels:
app: ucp-server
template:
metadata:
labels:
app: ucp-server
spec:
containers:
- name: centos7-ucp-client-server
image: images/centos7-ucp-client-server
imagePullPolicy: Never
command: ["ucp_client_server"]
args: ["-p", "13579"]
restartPolicy: Always
We use the image created in the previous section: image: images/centos7-ucp-client-server
. The imagePullPolicy: Never
should be used only if the image is presented locally. See this page for more details. The deployment can be created using the following command.
$ kubectl apply -f ucp-server-deployment.yml
deployment.apps/ucp-server-deployment created
Run the following command to check the deployment is ready.
$ kubectl get deployment ucp-server-deployment
NAME READY UP-TO-DATE AVAILABLE AGE
ucp-server-deployment 1/1 1 1 15s
The output can be checked using Kubernetes command-line tool. We need to get Pod name created by the deployment.
$ kubectl get pods -l app=ucp-server
NAME READY STATUS RESTARTS AGE
ucp-server-deployment-6d668586c-cbh2n 1/1 Running 0 6m17s
We use selector app=ucp-server
to dump the information only about the pod created by the deployment. We can use the name to dump the logs.
$ kubectl logs ucp-server-deployment-6d668586c-cbh2n
server is listening on IP 0.0.0.0 port 13579
Note that the server is listening on the port set in the deployment ucp-server-deployment.yml
.
The deployment can create and destroy Pods dynamically to run your application. We need to create a service to have a permanent address to the server side, so that clients can interact with it.
apiVersion: v1
kind: Service
metadata:
name: ucp-server-svc
spec:
selector:
app: ucp-server
ports:
- port: 13579
targetPort: 13579
We use the selector app: ucp-server
to set the service to the our previously created deployment. The port is the same as we set in the ucp-server-deployment.yml
. The service can be created with the same command as we use for the deployment creation.
$ kubectl apply -f ucp-server-svc.yml
The address can be found using the following command.
$ kubectl get svc ucp-server-svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ucp-server-svc ClusterIP 10.103.162.136 <none> 13579/TCP 3m47s
We can start the client part as a pod. We use the address and the port of the service ucp-server-svc.yml
. The container configuration is the same as for the deployment.
ucp-client-pod.yml
apiVersion: v1
kind: Pod
metadata:
name: ucp-client-pod
spec:
containers:
- name: centos7-ucp-client-server
image: images/centos7-ucp-client-server
imagePullPolicy: Never
command: ["ucp_client_server"]
args: ["-a", "10.103.162.136", "-p", "13579"]
Use the following command to create the pod.
$ kubectl apply -f ucp-client-pod.yml
Check the output of the application.
$ kubectl logs ucp-client-pod
Client: iteration #1
------------------------------
ABCDEFGHIJKLMNO.
------------------------------
received FIN message
We can set environment variable to debug UCX library.
$ kubectl set env deployment/ucp-server-deployment UCX_LOG_LEVEL=debug
The command will terminate existing pod, and create the new one. We use env
to set the environment variable for the client side.
ucp-client-debug-pod.yml
apiVersion: v1
kind: Pod
metadata:
name: ucp-client-debug-pod
spec:
containers:
- name: centos7-ucp-client-server
image: images/centos7-ucp-client-server
imagePullPolicy: Never
command: ["ucp_client_server"]
args: ["-a", "10.103.162.136", "-p", "13579"]
env:
- name: UCX_LOG_LEVEL
value: debug
The rest is the same as ucp-client-pod.yml
. The command line is also almost the same.
kubectl apply -f ucp-client-debug-pod.yml
Use the commands from the previous sections to check that the output of the application contains UCX library debug information.