adding a new port to an existing deployment kubernetes

11/19/2019

I deployed a new application that use port 80 using kubectl, and forgot to add the port 443 on the deployment, I exposed the port 80 for the application through the load balancer, But now I need to add port 443 to my deployment.

Any help is appreciated

-- Jaouad ALLALI
kubernetes

2 Answers

11/20/2019

as you can see I added a new port definition 443 to the yaml file, but when saving it says

k8sadmin@k8s-master-34239724-0:~$ kubectl edit deployment wordpress -oyaml error: deployments.extensions "wordpress" is invalid A copy of your changes has been stored to "/tmp/kubectl-edit-dtzxq.yaml" error: Edit cancelled, no valid changes were saved.

Here is the definition

creationTimestamp: 2019-11-18T12:27:57Z generation: 1 labels: app: wordpress name: wordpress namespace: default resourceVersion: "233695" selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/wordpress uid: da5a75cf-09fe-11ea-bfe8-001dd8b70024 spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: app: wordpress tier: frontend strategy: type: Recreate template: metadata: creationTimestamp: null labels: app: wordpress tier: frontend spec: containers: - env: - name: WORDPRESS_DB_HOST value: wordpress-mysql - name: WORDPRESS_DB_PASSWORD valueFrom: secretKeyRef: key: password name: mysql-pass image: wordpress:4.8-apache imagePullPolicy: IfNotPresent name: wordpress ports: - containerPort: 80 name: wordpress protocol: TCP - containerPort: 443 name: wordpress443 protocol: TCP resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File volumeMounts:

-- Jaouad ALLALI
Source: StackOverflow

11/19/2019

You can edit the deployment and make the changes or patch the deployment using kubectl patch command.

To edit the deployment use the below command

kubectl edit deployment <depoloyment-name> -oyaml

add the changes and save the file.

-- P Ekambaram
Source: StackOverflow