k8s deploy #614

Merged
telackey merged 5 commits from dboreham/k8s-deploy into main 2023-10-27 16:19:44 +00:00
3 changed files with 19 additions and 3 deletions
Showing only changes of commit 9c226944e8 - Show all commits

View File

@ -71,7 +71,7 @@ class ClusterInfo:
spec=client.V1PodSpec(containers=containers),
)
spec = client.V1DeploymentSpec(
replicas=3, template=template, selector={
replicas=1, template=template, selector={
"matchLabels":
{"app": self.app_name}})

View File

@ -17,6 +17,7 @@ from kubernetes import client, config
from app.deploy.deployer import Deployer
from app.deploy.k8s.helpers import create_cluster, destroy_cluster, load_images_into_kind
from app.deploy.k8s.helpers import pods_in_deployment
from app.deploy.k8s.cluster_info import ClusterInfo
from app.opts import opts
@ -24,6 +25,7 @@ from app.opts import opts
class K8sDeployer(Deployer):
name: str = "k8s"
k8s_client: client
k8s_api: client.AppsV1Api
kind_cluster_name: str
cluster_info : ClusterInfo
@ -84,8 +86,13 @@ class K8sDeployer(Deployer):
pass
def logs(self, services, tail, follow, stream):
# Call the API to get logs
pass
self.connect_api()
pods = pods_in_deployment(self.k8s_api, "test-deployment")
if len(pods) > 1:
print("Warning: more than one pod in the deployment")
k8s_pod_name = pods[0]
log_data = self.k8s_api.read_namespaced_pod_log(k8s_pod_name, namespace="default", container="test")
print(log_data)
def run(self, image, command, user, volumes, entrypoint=None):
# We need to figure out how to do this -- check why we're being called first

View File

@ -13,6 +13,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
from kubernetes import client
import subprocess
from typing import Set
@ -38,3 +39,11 @@ def destroy_cluster(name: str):
def load_images_into_kind(kind_cluster_name: str, image_set: Set[str]):
for image in image_set:
_run_command(f"kind load docker-image {image} --name {kind_cluster_name}")
def pods_in_deployment(api: client.AppsV1Api, deployment_name: str):
# See: https://stackoverflow.com/a/73525759/1701505
deployment_info = api.read_namespaced_deployment(deployment_name, "default")
if opts.o.debug:
print(f"deployment: {deployment_info}")
return []