I tried moving the container with Hatoba
Hello everyone. This is an article from the third day of Fujitsu Cloud Technologies Advent Calendar 2019.
Nifukura provides a container service called Hatoba. Click here for service introductions.
Hatoba is a service provided by Nifukura that makes it easy to build and manage Kubernetes clusters. The clusters we build at Hatoba are managed by Nifukura. The standard operation in Kubernetes allows containerized applications to be deployed on a cluster. Today, we're going to use this service to deploy containers.
We will create an environment for operation on Nifukura. In this article, we will use VMware Photon OS 3.0. First of all, let's make docker work. From the Nifukura Control Panel, select VMware Photon OS 3.0 to create a server. When it starts, connect with ssh and create an environment where docker works.
systemctl start docker
Make sure the dockre command works properly.
Let's also log in.
Create a directory to store the application.
mkdir demo-app cd demo-app
Make a simple application to make a container. It is implemented using a framework called Python's flask.
mkdir src vi src/app.py
Since there was a minimal application example, we will use it.
from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return "Hello World!" if __name__ == '__main__': app.run()
Prepare a container to run the application you created. Make a Dockerfile where Flask will work in a python container.
FROM python:3.6 RUN pip install Flask ARG project_dir=/projects/ ADD src/app.py $project_dir WORKDIR $project_dir CMD flask run --host 0.0.0.0 --port 5000
Create a container and see how it works.
docker build -t demo-app . docker run -d -p 5000:5000 demo-app
Try connecting to the container you started.
curl -s http://127.0.0.1:5000
「Hello world!」 was displayed.
Register the container with DockerHub.
docker image tag demo-app <DockerID>/demo-app:v1 docker image push <DockerID>/demo-app:v1
Now, let's create a Kubernetes environment to make this container work. Log in to Nifukura and select Hatoba.
Select Firewall from the left menu to keep the ports you need for access open:
|31500||For Flask applications|
Select a cluster from the left menu to create a cluster. When you select a cluster, the following screen is displayed.
To create a cluster, click the Create Cluster button.
Enter and select the necessary items and click the [To set up node pool] button.
Enter and select the necessary items and click the [Confirm] button.
Confirm the contents and click the [Create] button.
When it is launched successfully, you will see the above screen.
To get started, install the command.
tdnf -y install kubernetes-kubectl-extras ln -s /opt/vmware/kubernetes/linux/amd64/kubectl /usr/local/bin
Next, prepare to use kubectl. Register cluster credentials for the connection. Select the cluster from the Control Panel and select Credential View.
Copy the displayed credentials and create a
mkdir ~/.kube vi ~/.kube/config
Check if kubectl works properly.
kubectl get nodes
If you can get the information of the created node, you are done.
Register the container in the created cluster. The definition file of the application to be registered is called
apiVersion: apps/v1 kind: Deployment metadata: name: app-flask labels: app: app-flask spec: replicas: 3 selector: matchLabels: app: app-flask template: metadata: labels: app: app-flask version: v1 spec: containers: - name: app-flask image: <DockerID>/demo-app:v1 command: ["flask"] args: - "run" - "--host" - "0.0.0.0" - "--port" - "5000" ports: - containerPort: 5000 --- apiVersion: v1 kind: Service metadata: name: app-flask spec: type: NodePort selector: app: app-flask ports: - protocol: TCP port: 5000 name: app-flask nodePort: 31500
Register your application.
kubectl apply -f demo.yaml --record
View the node pool and check the configured global IP from the control panel, and make the connection as if you checked locally.
# curl -s http://<PodのIPアドレス>:31500
「Hello world!」 Did you see that?
What do you think? With Hatoba, it's easy to try out Kubernetes.
Tomorrow will be an extension of @tmtms's MySQL Parameters.